简体   繁体   中英

how can i get the source address of an uploaded file in asp.net c#

I need the actual location of the file that i have just uploaded via a file upload control in asp.net. I've tried using

string fileName = Path.GetFullPath(fUpldGetDoc.PostedFile.FileName);

but this returns

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\angel from montegomery.txt

but I need the actual location of the file ie,

e:\angel from montegomery.txt

As far as I can remember, this is not a portable feature in most browsers.

IE7 might (?) be able to support it, but most other browsers (FireFox, Opera, Chrome) seem to say that the filename is supported, but the path is hidden for privacy/security reasons. (IIRC some browsers will even 'make up' some noticeably bogus path so you will clearly see that it has been replaced for security reasons)

I don't currently have the time to quote a source on that, but for now this is my info

EDIT : Information outlining the behavior across browsers when using this property .

HttpPostedFile.FileName should provide you with the FQ path of the file on the client's machine.

HttpFileCollection MyFileColl = Request.Files;
HttpPostedFile MyPostedFile = MyFileColl.Get(0);
String MyFileName = MyPostedFile.FileName;

Keep in mind that the browser can return whatever it wants , opting to hide portions of the path if it so desires.

All in all the actual path on disk is irrelevant since you have the data in the HttpPostedFile as well as the name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM