how to read from file and display in a web page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhatta422
    New Member
    • Feb 2008
    • 2

    how to read from file and display in a web page

    i am a begineer at ASP.NET and c#.NET i am trying to learn on my own...
    please help me to read a file and display the content of the file in the web page. the file is formatted and saved in the .DOC format. i am not able to even read and display the .TXt file
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by bhatta422
    i am a begineer at ASP.NET and c#.NET i am trying to learn on my own...
    please help me to read a file and display the content of the file in the web page. the file is formatted and saved in the .DOC format. i am not able to even read and display the .TXt file
    To read a .txt, just use the TextReader class.
    To read .doc files you can look up Microsoft.Offic e.Interop.Word. Application (you have to have word installed).

    Comment

    • Sameerlucky
      New Member
      • Feb 2008
      • 6

      #3
      bhatta,

      Go thru the below example..Wil b quite helpful to u...

      This program just demonstrate the use of FileStream & StreamReader. The program take 1 parameter from the user i.e. the file to read.

      using System;
      using System.IO;
      class FileRead
      {
      string filereadbuf; // buffer to store the content of file
      public void ReadFile(string FileName, int FileSize)
      {
      char[] buf = new char[FileSize]; // lets define an array of type char field (i.e. variable) buf
      // for more help please see .net sdk
      StreamReader sr = new StreamReader(ne w FileStream(File Name, FileMode.Open, FileAccess.Read ));
      int retval = sr.ReadBlock(bu f, 0, FileSize); // no. of bytes read
      Console.Write ("Total Bytes Read = " + retval + "\n");
      filereadbuf = new string(buf); // store it in our field
      Console.WriteLi ne (filereadbuf); // lets print on screen
      sr.Close();
      }
      }

      cheers,
      Sameer

      Comment

      Working...