Question : Referencing text file in WPF application

Hi,

I am building a C# WPF application in VS2008 where I need to use a text file. In my development machine it is placed in the root of my application. From the application I can reference it using:

string filename = @"..\..\currencies.txt";

and everything works fine.
Now, When I deploy the application the path produced by the above line translates to "C:\Program files\currencies.txt". How can I make this file reference so it works correct both in my development machine and deployed to a client machine? In the deployment project the file (currencies.txt) is placed in the Application folder and the correct path should be "C:\Program Files\RT solutions\ReceiptScan\currencies.txt".

Best regards
RTSol
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
private void launchNotepad()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "Notepad.exe";
            currURI = @"..\..\currencies.txt";
            startInfo.Arguments = currURI;
            Process process = Process.Start(startInfo);
            process.EnableRaisingEvents = true;
        }

Answer : Referencing text file in WPF application

hence, your code should look like this:
1:
2:
3:
4:
5:
6:
7:
8:
private void launchNotepad()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "Notepad.exe";
            startInfo.Arguments = Path.Combine(Directory.GetCurrentDirectory(),"currencies.txt");
            Process process = Process.Start(startInfo);
            process.EnableRaisingEvents = true;
        }
Random Solutions  
 
programming4us programming4us