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\curr encies.txt ".
Best regards
RTSol
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\curr
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(Dir ectory.Get CurrentDir ectory(), "currencies.txt");
startInfo.Arguments = System.IO.Path.Combine(Dir
ASKER
Works fine! thanks a lot.
ASKER
I realized that it was ambigious so I used the full assembly path - thanks!
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
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
as long as the txt file is in the same folder as the exe.