Windows 10 Universal Apps – Read a file from within app container

Let’s say you want to include content files in you Windows 10 Universal App (text, XML, etc.) and then read content from those file to display inside your app.

For example, you’ve created “DataContent” folder inside your Visual Studio 2015 project, and placed sample.txt file inside.

To read that file, use the following code:

private async void ReadSampleFile()
StorageFile sampleFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///DataContent/sample.txt"));

string text = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s