Click here to Skip to main content
14,355,397 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to find a way to get a relative path for a text file in my Visual Studio, C#, WPF solution.

Right now i have something that works great on my computer, but if the application is run on another computer it breaks when the text file is needed, because the file path is different.

Here is my current code:
StreamWriter File = new StreamWriter("C:\\User Program Files\\anything you want\\team-4\\Maths Formula App\\ParabolaInfo.txt");

File.Write(___informationBox_.Text);
File.Close();


var text = File.ReadAllText("C:\\User Program Files\\anything you want\\team-4\\Maths Formula App\\ParabolaInfo.txt");
           
___informationBox_.Text = text;



so i need a way to get the file with a relative path that i can understand.

What I have tried:

I have searched the internet and other websites like this one, but none of the answers make any sense to me.

Thank you.
Posted
Updated 3 days ago

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The simple answer is: you don't.
Basically, you are storing your data files in the wrong place - you need to stroe them in a "safe" folder. Have a look here: Where should I store my data?[^] - it shows how to use places that will work on any computer.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100