Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.
Posted 15-Mar-11 20:32pm
Edited 15-Mar-11 20:43pm
m@dhu29.5K
v2
Comments
AlbinAbel at 16-Mar-11 2:01am
   
You want client path name? not allowed
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Server.MapPath will map to the Server's path.
 
So,
 
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.
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 1

string path = FileUpload1.PostedFile.FileName;
 
See here[^]
  Permalink  
v2
Comments
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
good
Please Sign up or sign in to vote.

Solution 3

Let me explain it to you step by step.
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.
  Permalink  
Comments
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 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 16 Mar 2011
Copyright © CodeProject, 1999-2014
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