Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant see JSON file in project

using VS 2013, C#

I am trying to use JSON file in my project. Using next code (as in sample project from MS):

        Uri dataUri = new Uri("ms-appx:///DataModel/MyData.json");
        StorageFile fileToRequest = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
        string jsonText = await FileIO.ReadTextAsync(fileToRequest);
        JsonObject jsonO = JsonObject.Parse(jsonText);
        JsonArray jsonA = jsonO["Events"].GetArray();

As result got this:

enter image description here

and next step - exception file not found, but it exists

enter image description hereenter image description here

Also, if the same code launched with sample project from VS - all its ok. Code from sample project:

        Uri dataUri = new Uri("ms-appx:///DataModel/SampleData.json");
        StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
        string jsonText = await FileIO.ReadTextAsync(file);
        JsonObject jsonObject = JsonObject.Parse(jsonText);
        JsonArray jsonArray = jsonObject["Groups"].GetArray();

Debugging of this code got:

enter image description here

So question - why I got exception FileNotFound, why this file invisible for my project.

like image 424
hbk Avatar asked Feb 23 '14 16:02

hbk


1 Answers

Oh finnally found reason

If you want to use JSON file need to make next: In properties set Build Action: Content, and Copy to Output Directory: Copy Always

enter image description here

Also found answer here. Also found this and this link useful. Maybe it can be helpful for someone.

like image 100
hbk Avatar answered Sep 30 '22 05:09

hbk