4

When I'm using the file upload control I just get only the file name, but I want to get the full path of the file location.

How do I get the full path from the file upload control in ASP.NET?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Leema
  • 97
  • 3
  • 13
  • 1
    possible duplicate of [Get full path of a file with FileUpload Control](http://stackoverflow.com/questions/1130560/get-full-path-of-a-file-with-fileupload-control) – ChrisF Sep 27 '10 at 11:27

4 Answers4

6

This is not possible in any browser, as a security measure.

If this were possible, an attacker could gain information regarding how files/folders were structured on a client computer.

Why do you need this information?

Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

You cannot get it because the browser does not send it. It would be dangerous if the browsers sent the full path at user's system.

Karel Petranek
  • 15,005
  • 4
  • 44
  • 68
0

If you are using the ASP.NET upload control, on client side you can get the full path like the following.

   document.getElementById('UploadControl').value

On the server side,

  UploadControl.PostedFile.FileName

Check the MSDN article HttpPostedFile.FileName Property for more information.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RameshVel
  • 64,778
  • 30
  • 169
  • 213
-2

I think you got file path of the upload control

HttpPostedFile httpBrowseFile = FileUpload1.PostedFile;
int FileLength = httpBrowseFile.ContentLength;
byte[] myData = new byte[FileLength];

httpBrowseFile.InputStream.Read(myData, 0, FileLength);
FName = path + FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf('\\') + 1);
Oded
  • 489,969
  • 99
  • 883
  • 1,009
Aman
  • 1,445
  • 2
  • 13
  • 11