Io.new Method [AX 2012]
Creates a new instance of the Io class.
The mode parameter can be one of the following modes:
-
R – read
-
W – write
-
A – append (implies W)
-
T – translate (text)
-
B – binary
A run-time error occurs if the file is accessed with a method that does not correspond to the current opened mode (for example, if an attempt is made to write to a read-mode file).
If an attacker can control input to the new method, a security risk exists. Therefore, this method runs under Code Access Security. Calls to this method on the server require permission from the . Ensure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.
This example uses the Io class to write to ExampleFile.
void IoExample()
{
Io io;
container con;
FileIoPermission perm;
#define.ExampleFile(@"c:\test.txt")
#define.ExampleOpenMode("w")
// Grants permission to execute the
// Io.new method.
// Io.new runs under code access security.
perm = new FileIoPermission(#ExampleFile, #ExampleOpenMode);
if (perm == null)
{
return;
}
perm.assert();
io = new Io(#ExampleFile, #ExampleOpenMode);
if (io != null)
{
io.write("Test");
}
// Close the code access permission scope.
CodeAccessPermission::revertAssert();
}