Click here to Skip to main content
15,901,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everybody!!
i want to know that how to get the address of a file saved in PC anywhere..
to get its full path using c# window application...i only know the file name but not its address where it is saved..how to do this???
Posted
Comments
lukeer 25-Jul-13 5:52am    
There can be myriads of files on one single harddrive of one PC that all have the same name. Without further information, you simply cannot tell which of them is the one you're looking for.

CPallini advises a search. I second that. If there are more results than one, let the user chose which one is the one in question.

You probably need to search a file based on its filename, anywhere in your PC.
See for instance: How to recursively search directories by using Visual C#[^].
 
Share this answer
 
Comments
lukeer 25-Jul-13 5:32am    
Countered the univote. This is the only viable among the given solutions in respect to the available information from OP.
CPallini 25-Jul-13 11:48am    
Thank you very much.
Hi. your question isn't obvious. do you perform saving operation ?
if you use saveFileDialog.Create a button and try this:
C#
private void GetPathButton_Click(object sender, RoutedEventArgs e)
       {
           string filePath = "";
           SaveFileDialog saveFileDialog = new SaveFileDialog();
           bool? result = saveFileDialog.ShowDialog();
           if (result.Value)
           {
               //To get full path
               filePath = saveFileDialog.FileName;

               //To get file name
               string fileName = saveFileDialog.SafeFileName;
           }
       }
 
Share this answer
 
Hi,
you can use the class System.IO.FileInfo

C#
fileInfo= new FileInfo(fileName);

fileInfo.DirectoryName; //This will give the folder path which is having the file


source...
 
Share this answer
 
Comments
lukeer 25-Jul-13 5:31am    
The FileInfo constructor[^] you advise does need the path to be included in its fileName parameter. Therefore it has to be known already.

Or, if you just pass the filename without path, it is regarded as relative to the working directory. That does not necessarily correlate with the path of any given file.

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