Nevron Open Vision Documentation
Files

The NFile class contains properties and methods for working with files in a platform independent way. In most cases you will get instances of the NFile class using file open and save dialogs or using the GetFile or GetFiles methods of an NFolder instance, but whenever necessary you can also create an NFile instance for a file system path by using the GetFile method of the NFileSystem class.

The methods of the NFile class are organized into the following major categories:

Working with Streams

The following methods of the NFile class lets you create, read and write files:

Since some platforms can't read files synchronously, all of the file manipulation methods mentioned above are asynchronous and work with callbacks. For example, to read the content of a file as an UTF-8 encoded string, you can use the following piece of code:

Read File
Copy Code
NFile file = NFileSystem.GetFile(@"C:\Documents\MyFile.txt");
file.OpenRead(
    delegate (Stream stream)
    {
        using (stream)
        {
            byte[] fileData = NStreamHelpers.ReadToEnd(stream);
            string fileContents = NEncoding.UTF8.GetString(fileData);
        }
    },
    delegate (Exception ex)
    {
        // Reading of the file failed
    }
);
Working with Files

NFile provides the following methods to work directly with files:

For example to read a file as UTF-8 encoded string, you can use the following piece of code:

Read File
Copy Code
NFile file = NFileSystem.GetFile(@"C:\Documents\MyFile.txt");
file.ReadAllBytes(
    delegate (byte[] fileData)
    {
        string fileContents = NEncoding.UTF8.GetString(fileData);
    },
    delegate (Exception ex)
    {
        // Reading of the file failed
    }
);
File System Info and Manipulation

These following methods of the NFile class aids you in working with the file system:

The methods above are also available as static methods of the NFile class.

The NFile class provides the following properties:

See Also
Send Feedback