By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,350 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,350 IT Pros & Developers. It's quick & easy.

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

P: 28
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.
Jun 21 '08 #1
Share this Question
Share on Google+
2 Replies

Curtis Rutland
Expert 2.5K+
P: 3,256
To upload the file, you can use the FileUpload control:
Expand|Select|Wrap|Line Numbers
  1. <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.
Expand|Select|Wrap|Line Numbers
  1. //c#
  2. using System.IO;
  3. .
  4. .
  5. .
  6. FileStream fs = new FileStream("pathToFile.txt", FileMode.Open, FileAccess.Read);
  7. 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.Office.Interop.Excel" 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.
Jun 22 '08 #2

P: 28
Thanksssssss It works
Jun 24 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.