web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Sample file import with StreamReader

PA-22040759-0 Profile Picture PA-22040759-0 6,194
Here is one example of how you can import files with .NET's StreamReader:
static void ImportWithStreamReader(Args _args)
{
    Filename                filename = @'C:\Temp\importme.txt';          
    System.IO.StreamReader  reader;
    System.String           line;
    InteropPermission       interopPermission;
   
    interopPermission = new InteropPermission(InteropKind::ClrInterop);
    interopPermission.assert();

    reader = new System.IO.StreamReader(filename, 
                                       System.Text.Encoding::get_UTF8());

    line = reader.ReadLine();

    while (!System.String::IsNullOrEmpty(line))
    {
        // Do something with line

        line = reader.ReadLine();
    }

    reader.Close();
    reader.Dispose();
}
If you can work with the file as on big chunk of text you can get away with just reading once, using the ReadToEnd method.

Read more about StreamReader on MSDN.

Comments

*This post is locked for comments