开发者

Problem getting the full path of the file uploaded using HTML inputfile type to read the content of the file

I would like to use HTML input file type in my aspx page to allow user to browse for a excel file and then read the content of the excel sheet programmatically.If I want to read the excel sheet I need the full path of the file to connect to the excel sheet using asp.net.I do not understand how can I get the full path of the file.

I know I can get the filename using postedFile.FileName property.But I need the full pa开发者_运维技巧th of the file.

Could someone please help me with that.

Thanks.


There's no such notion as full path of the file. The server has no way of knowing where the file is stored on the client computer. All that you can know in your ASP.NET application is the filename and the contents of the uploaded file.


You can use the OpenXml SDK (http://msdn.microsoft.com/en-us/library/dd608815(office.14).aspx) to open the Excel sheet programatically, directly from the stream of the fileupload.

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;

FileUpload fu = (FileUpload)Page.FindControl("fuExcel");
using (SpreadsheetDocument uploadedWorkbook =
SpreadsheetDocument.Open(fu.FileContent, true))
{
    //interrogate the file here
}

The FileUpload control doesn't provide any information regarding the path where the file was uploaded from. You get:

  • The file's name (that is, abc.xyz, stripped of any path information), as FileName
  • A stream of the file content as FileContent
  • An array of bytes in the file as FileBytes
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜