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 开发者_JS百科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:
string uploadedFilePath = "URL" + System.IO.Path.GetFilename(fileUpload1.FileName));
fileUpload1.SaveAs(uploadedFilePath);
2- Assign the value of your connString
variable:
switch ( postedfile.Substring(postedfile.LastIndexOf('.') + 1) )
{
case "xls":
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + uploadedFilePath + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";
break;
case "xlsx":
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + uploadedFilePath + ";Extended Properties=Excel 12.0;HDR=Yes;IMEX=2";
break;
}
Check to the following link:
http://weblogs.asp.net/ashicmahtab/archive/2009/05/20/fileupload-control-doesn-t-give-full-path-help.aspx
精彩评论