开发者

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:\Prog开发者_运维技巧ram Files\Microsoft Visual Studio 9.0\Common7\IDE\angel from montegomery.txt

but I need the actual location of the file i.e,

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜