1. I have to use the FileUpload control and save the file. 2. Open the saved file and read the contents.
1. This is the code I have to save the file
if (FileUpload1.HasFile)
{ FileUpload1.SaveAs(@"C:\temp\SampleLocationTest.xls");
_lblResult.Text = "File Uploaded: " + FileUpload1.FileName; }
2. This is the code I use to open and read the contents of the file.
string filename = FileUpload1.FileName;
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename +";Extended Properties='Excel 12.0;HDR=YES;'";
string strSQL = "SELECT * FROM [Sheet1$]";
OleDbConnection excelConnection = new OleDbConnection(connectionString); excelConnection.Open(); // This code will open excel file. OleDbCommand dbCommand = new OleDbCommand(strSQL, excelConnection);
OleDbDataAdapter dataAdapter = new OleDbDataAdapte ...
Go to the complete details ...