I have created a WPF project and added a "ResFiles" folder to my solution. Inside this folder I have put couple of XML files. In code, to access these files I am using relative path as described below.
using (StreamWriter writer = new StreamWriter(@"../../ResFiles/xyz.xml"))
{
serializer.Serialize(writer, mydata, ns);
}
This is working fine. But when I create setup project for my app, the folder structure is changing and the path given wont work. It is throwing file not found exceptions. How to tackle this path issue?
you can try this
var f = File.ReadAllText(System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) + @"/Files/file.txt");
and also you need to change Build Action and Copy to Output Directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With