Partilhar via


CommaIo.newmethod(String, String) Method

Definition

Creates a new object of the CommaIo class.

public:
 override void newmethod(System::String ^ _filename, System::String ^ _mode);
public override void newmethod (string _filename, string _mode);
override this.newmethod : string * string -> unit
Public Overrides Sub newmethod (_filename As String, _mode As String)

Parameters

_filename
String

The mode that the file should be opened in. Specify the mode as follows:

_mode
String

The mode that the file should be opened in. Specify the mode as follows:

Remarks

A run-time error occurs if the file is accessed by using a method that does not correspond to the current mode. For example, an error occurs if a user tries to write to a file that is opened in read mode. If an attacker can control input to this method, a security risk exists. Therefore, this method runs under Code Access Security. Calls to this method on the server require permission from the FileIOPermission class. Make sure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.

The following example uses a CommaIO object to read from the ExampleFile file.

{ 
    CommaIo         io; 
    container       con; 
    FileIoPermission perm; 
    #define.ExampleFile(@"c:\test.txt") 
    #define.ExampleOpenMode("r") 
    perm = new FileIoPermission(#ExampleFile, #ExampleOpenMode); 
    if (perm == null) 
    { 
        return; 
    } 
    // Grants permission to execute the CommaIo.new method. 
    // CommaIo.new runs under code access security. 
    perm.assert(); 
    io = new CommaIo(#ExampleFile, #ExampleOpenMode); 
    if (io != null) 
    { 
        con = io.read(); 
    } 
    // Close the code access permission scope. 
    CodeAccessPermission::revertAssert(); 
}

Applies to