Click here to Skip to main content
14,775,877 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi I am using File Upload control in my web site. I want full path of that file from Where I am uploading that file.
I use.
string path = Server.MapPath(FileUpload1.PostedFile.FileName);

But giving me the path where I am saving that file and not the path from where i m picking that file....

I hope u understand my problem.
Updated 15-Mar-11 20:43pm
Albin Abel 16-Mar-11 2:01am
You want client path name? not allowed

Server.MapPath will map to the Server's path.


string path = Server.MapPath(FileUpload1.PostedFile.FileName);

is not correct.

And this would help you to solve your problem FileUpload loses directory path.[^]

I see no use in getting the uploader file location.
Ankur\m/ 16-Mar-11 2:07am
It covers all the points I wanted to tell. 5!
Venkatesh Mookkan 16-Mar-11 2:09am
Thanks man.
string path = FileUpload1.PostedFile.FileName;

See here[^]
Venkatesh Mookkan 16-Mar-11 1:44am
FileUpload1.PostedFile.FileName will return only the filename in FireFox and Chrome. IE return the full path. But the questionnaire asking for the path of the file.
m@dhu 16-Mar-11 1:45am
Yes updated my answer with the link regarding that. :)
Ankur\m/ 16-Mar-11 1:54am
That will not work. Security reasons. I am adding an answer for the same.
m@dhu 16-Mar-11 2:14am
Yes. The link I provided also explains the same.
Ankur\m/ 16-Mar-11 2:24am
Oh okay. I didn't check that, I was talking about the code that you provided. :)
Okay I have 4'ed it now. :)
Let me explain it to you step by step.

This actually gives you path of the uploaded file.

But in all the newer browsers (FF 3.6 series, Chrome, IE7+) this feature has been disabled due to security reasons. Any website should not need path of a file stored in client's systems because that gives the directory structure and may expose other important things to website owner.

So in your case, the above code returned only the file name.

Now when you added Server.MapPath to the file name, it maps it to the corresponding physical directory on the server. So it is giving you a server path.

Hope that makes it clear.
suhas gadhe 16-Mar-11 2:41am
hey thanx ankur....
i got it what do u want to say.....
thanx man....
Ankur\m/ 16-Mar-11 4:18am
You are welcome. You may also up-vote the answer. :)
Farzanatayeb 26-Feb-13 2:56am
Thanks ankur
Ankur\m/ 26-Feb-13 4:20am
You are welcome! You may also vote the answer up if it helped. That way it helps other people quickly check out the best answers.
Member 12383282 10-Mar-16 12:25pm
If I add Server.MapPath program gives path to project in Visual Studio.
Ankur\m/ 18-Mar-16 8:22am
That's right because that corresponds to your website directory.
Member 10850253 17-Nov-17 21:43pm
I have a question.
I use the

but this gives me the path of the project with the name of the file, and not the path of the actual file that I am uploading.
How can I fix this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900