I have a directory named Resources in my WPF project and I have a Settings.json inside that directory. I want to read content from that file. In file settings I have Build Action -> Embedded Resource and Copy to Output Directory -> Copy Always And I read the file like this :
using (StreamReader r = new StreamReader(@"/Resources/Settings.json"))
And I get the following exception :
{"Could not find a part of the path 'C:\Resources\Settings.json'."}
How can I make this read the file in that directory? Thanks
Since you've got your Build Action set to Embedded Resource, you probably want to use the Assembly.GetManifestResourceStream method.
For example:
using (Stream stream = assembly.GetManifestResourceStream("MyCompany.Namespace.Settings.json"))
using (StreamReader reader = new StreamReader(stream))
using (StreamReader r = new StreamReader(Application.StartupPath + @"/Resources/Settings.json"))
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