Reading and Deserialize Local Json file for Windows Store App

Hi All,

I'm trying to read a json file that is packaged with my app as soon as my app loaded. It is a json file that contins a list of Urls that is regarded a whitelisted url's.

But When I try to read the json file I get the following exception: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

I have set the Build Action of the json file to "Content", below asr a screen shot of my solution file structure, the json file content, and my methods. Please Help.

Screenshot of my solution file structure
Capture.PNG
WhiteList.json (Content)
[{"Url":"*.google.co.za/*"},
{"Url":"*.microsoft.com"},
{"Url":"*.experts-exchange.com/*"},
{"Url":"www.virginmoneycard.co.za"},
{"Url":"www.yahoo.com"}]

Open in new window



methods
public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }

        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var dataUri = new Uri("ms-appx:///WhiteListApp/Data/WhiteList.json");
            var file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
            var jsonText = await FileIO.ReadTextAsync(file);
        }
    }

Open in new window

DickSwartAsked:
Who is Participating?
 
Éric MoreauSenior .Net ConsultantCommented:
shouldn't your URI be just "ms-appx:///Data/WhiteList.json"
0
 
Éric MoreauSenior .Net ConsultantCommented:
Change  the copy to output directory property to anything but "do no copy"?
0
 
DickSwartAuthor Commented:
I changed it to "Copy always" and then tried "Copy if newer" but I still get an error:

An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll but was not handled in user code

Additional information: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
0
 
DickSwartAuthor Commented:
Thank you so very much I totally overlooked it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.