Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Can anyone help me to find full path without filename?

i have one file upload control on aspx page.
By selecting one file using that, i need to get path of that file without file name
how to get this?
Posted
Updated 8-Aug-19 20:34pm

Use
C#
Server.MapPath(FileUpload1.FileName);
to get full path.

Example:

C#
string filePath = Server.MapPath(FileUpload1.FileName);
 
Share this answer
 
Comments
Ankur\m/ 26-Feb-13 7:02am    
That will give the server mapped path where the file is saved. I guess he is looking for client's path.
just use this code
C#
string fileFullName = @"G:\MailData\a\b\data.txt";
or string fileFullName = Server.MapPath("data.txt");//consider it is in root directory of web folder.
string pathWithoutFileName = System.IO.Path.GetDirectoryName(fileFullName);

it will return only path(without filename) G:\MailData\a\b or web root directory phisical path without filename.
 
Share this answer
 
v3
Comments
Sweetynewb 26-Feb-13 7:17am    
yes i tried this but i can not use server.mappath()
It gives wrong path, i mean i want client path
Are you looking for the path on client's system? If yes, that is not possible. The modern browsers do not return the path details for obvious security reasons. The path exposes the directory structure of a client's system.
Basically the server never need to know the complete path. All it needs is the file name.

So why do you need a client's path? Do you have an intranet web application you are working on?
 
Share this answer
 
v2
Comments
Sweetynewb 26-Feb-13 7:21am    
i want to upload multiple files on server so i want to find folder from which i can upload multiple files.
Please help me to find out path an no. of files in that folder
Ankur\m/ 26-Feb-13 7:43am    
Is it not the clients that will upload the files? Why do you need the folder? Fileupload controls takes file name as an input and not foldername. It won't upload all files in a folder.
fjdiewornncalwe 26-Feb-13 9:00am    
You can't do that because a browser does not have permission to do this type of IO interaction with the system without elevated privileges.
here you can get just path not name !
C#
string[] Dir = FileUpload1.FileName.Split('\\');
string Path="";
for (int i = 0; i < Dir.Length; i++)
    Path += Dir[i] + "\\";

after this you can use Path !
 
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