Share via


BinaryIo.newmethod(String, String) Method

Definition

Creates an instance of the BinaryIo 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 to use to create the instance of the BinaryIo class.

_mode
String

The mode to use to create the instance of the BinaryIo class.

Remarks

If an attacker can control input to the new method, a security risk exists. Therefore, this method runs under class. Make sure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.

This example uses the BinaryIo class to read data from the ExampleFile text file.

static void BinaryIoExampleW2(Args _args)
{     
    #define.ExampleFile(@"D:\Folder\TestW.BinaryIo")
    #define.ExampleOpenModeW("w")
    #define.ExampleOpenModeR("r")
    BinaryIo binaryIoObject;
    container con1;
    str sConRecs;
    FileIoPermission perm;
    // Set the code access permission to help protect the use of
    // the BinaryIo.new method.
    perm = new FileIoPermission(#ExampleFile, #ExampleOpenModeW);
    if (perm == null)
    {
        return;
    }
    perm.assert();
    // Overwrites the file if it already exists; restarts it as empty.
    binaryIoObject = new BinaryIo(#ExampleFile, #ExampleOpenModeW);
    if (binaryIoObject != null)
    {
        info("w binaryIoObject is NOT null, Good.");
        binaryIoObject.write("hello world");
        binaryIoObject.write("goodbye solar system");
    }
    else
    {
        warning("w binaryIoObject is NULL, Bad.");
    }
    binaryIoObject.finalize();
    binaryIoObject = null;
    // Close the file, w
    // BinaryIo instance can only read files in that
    // are in the exact same esoteric format that BinaryIo
    // writes files to.
    // binaryIoObject = new BinaryIo(#ExampleFile, #ExampleOpenModeR);
    if (binaryIoObject != null)
    {
         info("r binaryIoObject is NOT null, Good.");
         while (true)
        {
            con1 = binaryIoObject.read();
            if (con1 == conNull())
            {
                info("r, no more records.");
                break;
            }
            sConRecs = con2Str(con1);
            info(sConRecs);
        }
    }
    else
    {
         warning("r binaryIoObject is NULL, Bad.");
    }
    binaryIoObject.finalize();
    binaryIoObject = null;
    WINAPI::deleteFile(#ExampleFile);
     // Clean up after the job.
    CodeAccessPermission::revertAssert();
 }
/*** Output copied from Infolog:Message (11:22:16 am)w binaryIoObject is NOT null, Good.r binaryIoObject is NOT null, Good.hello worldgoodbye solar systemr, no more records.***/

Applies to