FileNotFoundException reading JSON file from Assets folder in Windows Store app
c#, file-io, windows, windows-runtime, windows-store
Solution
In the properties of the file (Right click and properties) under Build Action have you made sure this is selected as Content? Also make sure that Copy to Output Directory is set as Copy Always. This should solve the problem for you I think.
Problem
I'm trying to read a `json` file from my Assets folder. I've tried numerous code examples, and all are variations on the same thing. I feel like I must be doing something stupid, but I just can't see it. ``` string filepath = @"Assets\resources.json"; StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFile file = await folder.GetFileAsync(filepath); // error here var data = await Windows.Storage.FileIO.ReadTextAsync(file); ``` Every time I run the above code I get a `System.IO.FileNotFoundException` on my app. I've double and tripled checked the file is in the assets folder and there are no typos in my path. I've also tried this ``` StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/resources.json")); ``` Same error. `System.IO.FileNotFoundException` Screenshot of my Assets folder: