Using ASP.NET to read and process file content Print

  • 2

File access is handled through the System.IO.File namespace. Using the Open method will allow you to read the contents of the file:

System.IO.File.Open(String, FileMode) {there are also 2 other overloads for this method}

Once the file has been opened, you can then read / process / output the contents of the file by calling the Read method, as follows:

fs = File.Open(path, FileMode.Open, FileAccess.Read)

Dim b(1024) As Byte

Dim temp As UTF8Encoding = New UTF8Encoding(True)

Do While fs.Read(b, 0, b.Length) > 0

Console.WriteLine(temp.GetString(b))

Loop

 

The Microsoft knowledgebase has more information and code samples available online:

http://msdn.microsoft.com/en-us/library/system.io.file.open(v=vs.71).aspx

 

Hope this helps


Was this answer helpful?

« Back