Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 8-Nov-19 19:52pm

1 solution

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.
 
Share this answer
 

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