I am trying to read an excel file from a client’s PC. I am using an ASP fileupload control. When I am trying to read the file, its trying to open the file selected in the wrong folder. The file is located on the D: drive and it is trying to open it in the C: drive.
The following is what I am passing into a function:
fpc.AddSpecs(ref model, this.fuSpecs.PostedFile.FileName.ToString());
The following is the connection string in the function:
switch ( postedfile.Substring(postedfile.LastIndexOf('.') + 1) )
{
case "xls":
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + postedfile + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";
break;
case "xlsx":
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + postedfile + ";Extended Properties=Excel 12.0;HDR=Yes;IMEX=2";
break;
}
What could be the problem?
1- Save the file on your server:
2- Assign the value of your
connStringvariable:Check to the following link:
http://weblogs.asp.net/ashicmahtab/archive/2009/05/20/fileupload-control-doesn-t-give-full-path-help.aspx