Get full path of a file with FileUpload Control

asp.netfile upload

I am working on a web application which uses the FileUpload control. I have an xls file in the full filepath 'C:\Mailid.xls' that I am attempting to upload.

When I use the command

FileUpload1.PostedFile.FileName 

I cannot get the full filepath from my system. However, when I use the above command in another system it works fine.

I also tried the following commands with no success:

   System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);
   Path.GetFileName(FileUpload1.PostedFile.FileName);
   System.IO.Path.GetDirectoryName(FileUpload1.PostedFile.FileName).ToString();
   Convert.ToString(System.IO.Directory.GetParent(FileUpload1.PostedFile.FileName));

How can I get full path?

Best Answer

It's currently true that "when you upload a file the browser will only send the source filename and not the full path" - it makes perfect sense that the server has no business knowing whether the file was in "C:\WINDOWS\" or "F:\SOMEDIR\OTHERDIR\PERSONALINFO\". The filename is always sent, and is useful both to help the user 'recognise' the content and possibly to interrogate the file extension to help determine the file type.

However I know from experience that Internet Explorer definitely used to (in older versions) send the entire path. It's difficult to find an authoritative confirmation (except this apache fileupload control doco)

Internet Explorer provides the entire path to the uploaded file and not just the base file name

Regardless, you should not use nor expect the full path to be sent by any 'modern' browser.

Related Topic