Reputation: 3
I am using fileupload control to get the path of the file.. But it gives me some "C:" path instead of the real path of the file..
how can i get the real path of the file uploaded.
I am using :
Path.GetFullPath(FileUpload1.FileName)
to get the file path..
but i am getting the path as:
"C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\+filename"
Upvotes: 0
Views: 684
Reputation: 499302
This is not possible as it would be a security risk.
It is not clear to me what path you are getting, as you should only be getting a file name - you should supply the path to where to save the file.
Edit:
You are getting the full path to the file - this shouldn't be happening and doesn't when using most browsers. However, IE does give the full path, even though it is a security hole.
Edit 2:
You are using Path.GetFullPath
and are supplying the filename only. When this happens, the current directory path is perpended to the filename. This would be the directory that your code is running from by default.
From MSDN:
The file or directory specified by path is not required to exist. For example, if c:\temp\newdir is the current directory, calling GetFullPath on a file name such as test.txt returns c:\temp\newdir\test.txt. The file need not exist.
Upvotes: 4
Reputation: 219047
Understand that what you're receiving on the server isn't a "file" in the sense of being on a file system. What you're receiving is a web request. It contains a header and data which was populated from a file, and you're likely to save it to the file system on the server. But by the time it comes in as a web request, it's not part of a file system and has no "path" to speak of.
The client would have to send the "path" as part of the request header, which doesn't shouldn't happen.
Upvotes: 1