tags:

views:

31

answers:

2

I have to import the contents of a spreadsheet in my asp.net project. The code behind is c#. I figured out how to locate the spreadsheet on the user's computer and how to import the data from a given worksheet into a datable. The problem is I may not know the name of the worksheet ahead of time. How do I present the user with a list of available worksheets and have them pick one?

Bob

+1  A: 

You cannot tell the ASP.NET page where to look on the user's PC for a file. If so, there would be nothing stopping you from snooping the user's entire machine and gathering personal information.

Your option is present the user with a file upload control (the most practical being the asp:FileUpload server control) and allowing the user to select which file to submit. If you need a greater deal of control than that, you are going to have to use something other than (or in addition to) ASP.NET, such as a winform or console app that resides on the user's machine.

Anthony Pegram
Hi Anthony, Thanks for responding. You seem to have misunderstood the question. I am not looking for how to find a file on the user's computer but rather how to list the worksheets in a spreadsheet than I've found.By the way, I found that AsyncFileUpload works better than FileUpload . I've had problems getting FileUpload to work.Bob
Bob Avallone
A: 

I found the answer:

OleDbConnection objConn = null; objConn = new OleDbConnection(pConnectionString); // where pConnectionString looks like // "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Source\Sheetname.xls;Extended //Properties=Excel 8.0;" // Opens connection with the database. objConn.Open(); // Get the data table containing the schema guid, and also sheet names. dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

the rows of dt (a datatable contains the worksheet names)

Bob Avallone