Click here to Skip to main content
14,268,797 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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

Example:

string filePath = Server.MapPath(FileUpload1.FileName);
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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

Solution 3

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

Solution 4

here you can get just path not name !
string[] Dir = FileUpload1.FileName.Split('\\');
string Path="";
for (int i = 0; i < Dir.Length; i++)
    Path += Dir[i] + "\\";

after this you can use Path !
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




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