Click here to Skip to main content
11,933,854 members (56,345 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.
Posted 15-Mar-11 20:32pm
Edited 15-Mar-11 20:43pm
AlbinAbel 16-Mar-11 2:01am
You want client path name? not allowed
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
mkgoud 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.
mkgoud 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. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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.

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

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 16 Mar 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100