Windows 8 Metro App development [6] accessing Assets folder

Source: Internet
Author: User

Windows. Storage namespace

First, we need to know the Windows. Store namespace.

If you read the Windows. Storage documentation provided by Microsoft MSDN, you will find a StorageFolder class in it. Through this class, we can operate folders and related content. The StorageFolder class has a method called StorageFolder. CreateFileAsync, which asynchronously creates a file in the current folder. At the same time, you will also see that there are methods to get the file content, read file attributes, and so on.

The operation code is as follows:

 

   async void MainPage_Loaded(object sender, RoutedEventArgs e)        {            StorageFolder InstalltionFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;            string CountriesFile = @"Assets\output.xml";            StorageFile file = await InstalltionFolder.GetFileAsync(CountriesFile);            Stream countries = await file.OpenStreamForReadAsync();            XDocument doc = XDocument.Load(countries);               }

Local XML file:

 

<?xml version="1.0" encoding="utf-8" ?><bookstore><book category="CHLDREN">  <title>Harry Potter</title>  <author>JK. Rowling</author>  <year>2005</year>  <price>39.95</price></book><book category="WEB">  <title>Harry Potter</title>  <author>JK. Rowling</author>  <year>2005</year>  <price>39.95</price></book></bookstore>

 

Here, we need to pay special attention to the async and await keywords, which are the new keywords in C #. Here we only need to know that we need to use them when calling asynchronous functions, I will explain async and await in detail in the subsequent study series.

Running effect:

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.