Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the ful path of a file when i give the file name in vb.net
Posted
Comments
Andy Lanng 16-Oct-15 5:04am    
You can't
If you have a file called new.txt in the root C: and root D:, then how could we tell which one is which?

What is your goal? How to you expect to achieve it? What code have you tried?

1 solution

The file name is not immediately matchable to a file - it contains no path information.
You can however get the application current path with
C#
string curPath = Directory.GetCurrentDirectory();
Or
C#
string assPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Or
C#
string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

which get you the path the assembly and application reside in respectively.

But...if you are writing to the file, you should look at keeping it in a defined location. Where should I store my data?[^] suggests some suitable places.
 
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