Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How can I create a file at the place where the application exe resides

eg :

my app is in

d:\data\app\app1.exe

now I want to create a file say xyz.txt at the end of execution

d:\data\app\xyz.txt


now if I move my app1.exe to c:\ it must create the file at c:\ without any change in code.

How can I achieve this ?

Thanks.....
Posted

Use just the name of the file as the path, e.g "xyz.txt".
 
Share this answer
 
Comments
iBrutus 14-Oct-10 4:37am    
exactly the thing I needed ....thanks a lot
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
 
Share this answer
 
This will give you the directory the current assemble is in
string myFile = System.AppDomain.CurrentDomain.BaseDirectory+@"\xyz.txt"
 
Share this answer
 
v2
you can use below code for create file

string filepath = Application.StartupPath+"xyz.txt";
if(!File.exist(filepath))
{
//code for create
}
 
Share this answer
 
string dirPath = Directory.GetCurrentDirectory();
After getting the path u should write your code for ctrating your file.
:)
 
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