Link to home
Start Free TrialLog in
Avatar of RTSol
RTSol

asked on

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
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;
        }

Open in new window

Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

From your application when u wish to reference the txt file u can use Directory.GetCurrentDirectory().
as long as the txt file is in the same folder as the exe.
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Path is declared in System.Windows.Shapes as well (besides System.IO), so u need to declare the full assembly path:

startInfo.Arguments = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "currencies.txt");
Avatar of RTSol
RTSol

ASKER

Works fine! thanks a lot.
Avatar of RTSol

ASKER

I realized that it was ambigious so I used the full assembly path - thanks!
Avatar of RTSol

ASKER

Hi again,

I ran into a little problem. I can open the file using notepad at the client but I can't save it back - access denied. How can I fix thsi?
If you want me to open a new question I will do so - let me know!

Best regards
RTSol