Read and write for files in Windows 8 development

Source: Internet
Author: User
Tags xmlns

The reading and writing of files should not be unfamiliar to us, but should be very familiar. In learning. NET other development technology, IO is what we have to learn, after all, that is the most basic data storage and processing operations.

In the development of Windows store applications, it is also necessary to read and write files, but because of security and permissions restrictions, we can not be as "free work" as before. It's good to know that "tile" applications are for mobile platforms, at least usually. If we want to be able to read and write freely as we have in the past, consider using a traditional desktop application.

In fact, what is called Windows 8 application development, and not just the store application, as long as the program that can run on win 8 we can say is the Windows 8 application, like the old-fashioned MFC, the previous Windows Form, and later WPF, and so on, can be merged into Windows 8 applications.

In a store application, there are usually two categories of directories we read and write, one for the Application Data folder and the other for the user's document library, and if you think ms-appx://and ms-appdata://are bad, you can simply not remember, Even if you do not know that this path notation will not affect you to write the program, as you believe it, I believe it anyway.

Now, let's take the first example of the text and see how to use the existing APIs to access the application's local data directory.

The first step, a new "tile" application project, this need not I said, here omitted 38 words.

The second step, layout, MainPage.xaml XAML is as follows:

<page x:class= "App1.mainpage" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "H" Ttp://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" Using:app1 "xmlns:d=" http://schemas.microsoft.com/ expression/blend/2008 "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "&  
      
    Gt   
            <grid background= "{StaticResource Applicationpagebackgroundthemebrush}" > <richtextblock Margin= ">" <paragraph fontsize= > <Span> Local storage directory:</span> <ru n x:name= "rnlocal"/> <LineBreak/> <LineBreak/> <sp  
                An> Roaming storage directory:</span> <run x:name= "rnroaming"/> <LineBreak/> <LineBreak/> <Span> Temporary directory:</span> <run x:name= "Rntemp"/&G  
           T </Paragraph> </RichTextBlock> </Grid> </Page> 

The third step, write C # code, although outside rumors everywhere, but I still like C #, after all, rumors from fools, stop in the wise.

protected override void Onnavigatedto (NavigationEventArgs e)  
{  
    This.rnLocal.Text = Windows.Storage.ApplicationData.Current.LocalFolder.Path;  
    This.rnRoaming.Text = Windows.Storage.ApplicationData.Current.RoamingFolder.Path;  
    This.rnTemp.Text = Windows.Storage.ApplicationData.Current.TemporaryFolder.Path;  
}

As you can see from the code above, why do I have to say that even if you don't remember the path's architectural approach it's easy to access these folders.

Let's just run it.

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.