Io.newmethod(String, String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a new instance of the Io class.
public:
virtual void newmethod(System::String ^ _filename, System::String ^ _mode);
public virtual void newmethod (string _filename, string _mode);
override this.newmethod : string * string -> unit
Public Overridable Sub newmethod (_filename As String, _mode As String)
Parameters
- _filename
- String
The mode in which the file should be opened.
- _mode
- String
The mode in which the file should be opened.
Remarks
The mode parameter can be one of the following modes:
Value | Mode |
---|---|
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. . 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();
}