Click here to Skip to main content
11,716,938 members (85,676 online)
Rate this: bad
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 19:32pm
Edited 15-Mar-11 19:43pm
AlbinAbel at 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/ at 16-Mar-11 2:07am
It covers all the points I wanted to tell. 5!
Venkatesh Mookkan at 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 at 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 at 16-Mar-11 1:45am
Yes updated my answer with the link regarding that. :)
Ankur\m/ at 16-Mar-11 1:54am
That will not work. Security reasons. I am adding an answer for the same.
mkgoud at 16-Mar-11 2:14am
Yes. The link I provided also explains the same.
Ankur\m/ at 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 at 16-Mar-11 2:41am
hey thanx ankur....
i got it what do u want to say.....
thanx man....
Ankur\m/ at 16-Mar-11 4:18am
You are welcome. You may also up-vote the answer. :)
Farzanatayeb at 26-Feb-13 2:56am
Thanks ankur
Ankur\m/ at 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
0 Sergey Alexandrovich Kryukov 659
1 F-ES Sitecore 260
2 Maciej Los 185
3 OriginalGriff 175
4 Richard MacCutchan 140
0 Sergey Alexandrovich Kryukov 1,029
1 Maciej Los 464
2 Richard MacCutchan 430
3 CHill60 415
4 OriginalGriff 415

Advertise | Privacy | Mobile
Web02 | 2.8.150901.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