Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
guys i have taken Fileupload control, Button and Textbox

so when i click on button i want full path of file from fileupload control in the Textbox
..
Posted
Updated 28-Oct-13 23:20pm
v9
Comments
samit kaneriya 29-Oct-13 3:13am    
u want code client side or server side ?
jackspero18 29-Oct-13 3:21am    
just simple web application of 1 web page when i click on button i want file path from fileupload control In textbox
Thomas ktg 29-Oct-13 4:59am    
I think this is not possible. The browser wont be able to post the full path. It is to make sure the security of the client computer.
samit kaneriya 29-Oct-13 5:03am    
sorry if u want to get client path location it not possible because it replace original of client with [fakepath] so not possible to trace client file location by server
jackspero18 29-Oct-13 5:18am    
ok.. then when i run my application on Local host atlist on the local server i can get my file path.....

Like below you can get full path of your file in fileupload contorl :

C#
string filePath,fileName;
   if (FileUpload1.PostedFile != null)
   {
       filePath = FileUpload1.PostedFile.FileName; // file name with path.
       fileName = FileUpload1.FileName;// Only file name.
   }


Or refer below link :

http://stackoverflow.com/questions/4242819/getting-the-path-of-a-file-using-fileupload-control[^]

Accept as answer and vote if help to you.
 
Share this answer
 
Comments
jackspero18 29-Oct-13 3:37am    
no its not getting file path...
getting file name..
jaideepsinh 29-Oct-13 3:47am    
You tried both :
filePath = FileUpload1.PostedFile.FileName; // file name with path.
fileName = FileUpload1.FileName;// Only file name.
jackspero18 29-Oct-13 3:48am    
ya both..... getting file name not path..
jaideepsinh 29-Oct-13 7:04am    
Use this:
string filePath = Server.MapPath("~/");
khaledeltaweel 18-May-16 7:06am    
work only in IE
Do in this way :

    String Path = HttpContext.Current.Request.PhysicalApplicationPath + FileUpload1.FileName;

Or try this  String Path = Server.MapPath(FileUpload1.FileName);


Hope this will help you :).
 
Share this answer
 
Comments
Member 12383282 10-Mar-16 10:48am    
both methods gives path to program diretory and +file name
You can try like this:-

C#
string fileBasePath = Server.MapPath("~/");
string fileName = Path.GetFileName(this.MyFileUploader.FileName);
string fullFilePath = fileBasePath + fileName;


Still if you not get path then its issue of browser security.
refer this:-
http://forums.asp.net/t/1077850.aspx[^]
 
Share this answer
 
Comments
jackspero18 29-Oct-13 5:18am    
No still its showing File name
Mas11 29-Oct-13 9:01am    
@jackspero18 >> can u write your code please, what you write.
Member 12369057 6-Apr-16 5:05am    
It is giving path but not file path instead it is giving project file path+ file name
Here i have given answer to the similar question.
Just look that, it will help you.

File Upload & saved in Sql Database[^]

Hope This Help
-------------------
Pratik Bhuva
 
Share this answer
 

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