Click here to Skip to main content
15,885,985 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.
C#
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.
Posted
Updated 15-Mar-11 19:43pm
v2
Comments
Albin Abel 16-Mar-11 2:01am    
You want client path name? not allowed

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

So,

C#
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.
 
Share this answer
 
Comments
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.
C#
string path = FileUpload1.PostedFile.FileName;


See here[^]
 
Share this answer
 
v2
Comments
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.
C#
FileUpload1.PostedFile.FileName

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.
 
Share this answer
 
Comments
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.

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



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