Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,

I am using C#.net 3.5 and creating Windows application. I want to set file path, which is in the project folder, currently I am using:

FileName = "D:\\test\\Migration\\Migration\\tools\\scanstate.exe";

But if i trie this project on another machine it needs to be changed again.

I have also tried FileName = @"..\\tools\\scanstate.exe"; but it's not working.
Can any one suggest to me the correct way to do this.

Thank you.
Posted
Updated 23-Apr-11 23:56pm
v2
Comments
Ed Nutting 24-Apr-11 5:56am    
Improved for spelling/grammer and readability and also code formatting.

Take a look at System.IO.Path[^] class, it performs operations on string instances that contain file or directory path information.

To read/write a file, that is located where your program runs, you can uses something like this:
string fileToRead = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\MyOtherFile.xml";

string allDataFromFile = System.IO.File.ReadAllText(fileToRead);
 
Share this answer
 
v2
yet another option would be

System.Windows.Forms.Application.StartupPath


good luck
 
Share this answer
 
Hi,

Try this,

FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + "\\scanstate.exe";


Regards,
Suresh
 
Share this answer
 
Comments
Prasanta_Prince 24-Apr-11 14:08pm    
Good one
it's same as System.Environment.getcurrentfolder().tostring();

it will return debug folder
 
Share this answer
 
i have one project.
in this project can't provide setupfile.ok
how can run a project. in c# visual stdio 2008.
 
Share this answer
 
v2

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