CommaIo.new Method
Creates a new object of the CommaIo class.
Syntax
public void new(str filename, str mode)
Run On
Called
Parameters
- filename
Type: str
The name of the file to open.
- mode
Type: str
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.
Examples
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();
}