views:

65

answers:

2

Hi.

I am trying to get the full path from the client for files that are submitted for upload.

I want something like:

C://this/is/your/file.jpg

But, when I try:

m_File = Request.Files[i];
m_File.FileName

I get "just" the file name.

And, when I try:

System.IO.Path.GetFileName(m_File.FileName)

I get a path that seems to point to my IDE:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PICT0736.JPG

I am using an HttpPostedFile collection on the server and hidden inputs with type=file (passed via iframe) to POST the file collection.

Ideally, I would like each input to have value="c://path/to/file.gif"

If you don't think this is possible or stylistically sound, I'd appreciate alternative suggestions (code examples especially appreciated).

Thanks for your efforts. :)

+3  A: 

Browsers typically won't give you the fully qualified path, to avoid sending potentially sensitive information to web servers.

Adam Goode
Thanks Adam. Any suggestions as to how to go about this? Thanks again.
Code Sherpa
A: 

As I understand it, when sending a file with HTTP post, you only send the contents of the file, which doesn't include file system metadata such as file path. The only way I could see to solve this would to include the metadata manaully with a POST. Perhaps using some javascript and a hidden input field on the form to capture the provided file path and update it as the path provided changes?

llamaoo7
Ah, that is a good idea. I could do that. Is there any reason that this method should be a security concern?
Code Sherpa
Making this information available that way would also be a security hole, and if any browser does that it should be fixed.
Roger Pate
There are plenty of forms over the web where the input displays the full file path to the file you want to upload and they work on all browsers. Should browsers that allow the "Browse..." dialog be fixed? Of course, someone could always put in a dummy path when uploading a file.
llamaoo7
It also depends what you want to do with the file path. I would base any IO operations off of it.
llamaoo7
llamaoo7, thanks I am looking into your solution and it seems straight forward enough. <br>R. Pate - fair enough. Would you please provide what the "fix" would be since you seem to have an opinion here.
Code Sherpa
OK... "simply" grabbing the full path from the source computer using JavaScript is not that easy. Could somebody please post code? Thanks.
Code Sherpa