Reputation: 793
I'm trying to read a json file from my project but vs can't find it. When I'm using the .txt
extension, everything is OK, but when I change extension to .json
, then the file is not found
string fileContent;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Resources/Database/text.json"));
using (StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync()))
fileContent = await sRead.ReadToEndAsync();
"The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"
Upvotes: 1
Views: 2198
Reputation: 6857
In order to use JSON file, you need to right click on the file in file explorer in Visual Studio and choose Properties, then in Advanced section:
1) set Build Action
to Content
2) set Copy to Output Directory
to Copy always
Upvotes: 4