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
WhiteList.json (Content)

Open in new window

public sealed partial class MainPage : Page
        public MainPage()
            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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Change  the copy to output directory property to anything but "do no copy"?
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)
Éric MoreauSenior .Net ConsultantCommented:
shouldn't your URI be just "ms-appx:///Data/WhiteList.json"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DickSwartAuthor Commented:
Thank you so very much I totally overlooked it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.