how to upload the file (Excel or Text file) from Client in ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • minhtran
    New Member
    • Feb 2008
    • 28

    how to upload the file (Excel or Text file) from Client in ASP.NET

    HI all
    I wish to get help from anyone as how can I upload a file as Excel file or Text from Client side to Webserver then we can read the file in ASP.NET or any code can read the file from client. Please, help me if you have any idea . Thank you so much in advance.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    To upload the file, you can use the FileUpload control:
    Code:
    <asp:FileUpload ID="FileUpload1" runat="server" />
    Then, once you have saved that file, you can use the System.IO library to read a text file. I suggest the StreamReader.
    Code:
    //c#
    using System.IO;
    .
    .
    .
    FileStream fs = new FileStream("pathToFile.txt", FileMode.Open, FileAccess.Read);
    StreamReader sr = new StreamReader(fs);
    Make sure that when you are done with them you call the .Close() methods on all your Streams.

    To read an excel file, you can use COM Interop. Right-click your solution, and click "Add Reference." Select the ".NET" tab and find: "Microsoft.Offi ce.Interop.Exce l" and click OK.

    Here's a good tutorial on creating Excel documents, you should be able to figure out how to read them from this.

    Comment

    • minhtran
      New Member
      • Feb 2008
      • 28

      #3
      Thanksssssss It works

      Comment

      Working...