C# .NET - Alternate of File upload control - Asked By sunny khetarpal on 21-Jan-10 04:59 AM

Hi,

need a solution when i browse for 1 file in IE it returns the full path but in mozilla it returns only a file name

Thanks
www.myzonal.com

Alternate of File upload control - Sagar P replied to sunny khetarpal on 21-Jan-10 05:11 AM

FireFox and other browsers see this as a security breach as the server has no right to know the directory structure of the client machine. Because of Security Concern , you didnt get the full path in Firefox, These browsers only hold the name of the file in FileName and not any path.

If you wish to save the file on the server, all you need to do is fileUpload1.SaveAs(...). The file is held in a temp location and you shouldn't need to (and shouldn't) use the path where it is uploaded to. If you need the file later on, just use SaveAs and save to a more convenient path.

Firefox sends the filename without path (IE sends full path); but that should still be enough to get a name. If you use Path.GetFileName(filename) you should have the same answer from either...

re - Santhosh N replied to sunny khetarpal on 21-Jan-10 05:12 AM

There are certain workarounds for this..

1) have the path set from the javascript to a hidden field and read from the hidden field on server side code

2) use path class and get the fullpath,

can check http://forums.asp.net/t/1072949.aspx for more info on this

See this solution which may help - Sagar P replied to sunny khetarpal on 21-Jan-10 05:13 AM

An alternate solution/fix... In FF3, You can retrieve file's full path in a text box instead of file browse box. And that too... By drag/dropping the file!

You can drag drop your file into a text box in your html page. and it will display the file's complete path. This data can transferred to your server easily or manipulate them.

All you have to do is... Use the extension DragDropUpload

http://www.teslacore.it/wiki/index.php?title=DragDropUpload

This extension will helps you in drag dropping files into your File Browse (Input file) box. But still you wont able to get the file full path, If you try to retrieve.

mv ark replied to sunny khetarpal on 30-Jan-10 11:13 PM
You may get the full path only in IE 7 & below. As a security feature, IE 8 & Firefox will not return the full path -
http://weblogs.asp.net/ashicmahtab/archive/2009/05/20/fileupload-control-doesn-t-give-full-path-help.aspx

You have to specifically enable the IE 8 option to include the local directory path for the Internet Zone on the client-side - http://blogs.msdn.com/webtopics/archive/2009/07/27/uploading-a-file-using-fileupload-control-fails-in-ie8.aspx

As this feature is not available on all browsers, its better to fetch this on the server-side rather than getting the path on the client-side