开发者

Get the full path from a file upload

开发者 https://www.devze.com 2023-01-17 13:29 出处:网络
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.

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 开发者_Go百科I get the full path from the file upload control in ASP.NET?


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?


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.


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.


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);
0

精彩评论

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