"Miles Journey--windows App development" file operation--read file

Source: Internet
Author: User

In the previous section we learned about data binding, because I personally am more satisfied with the previous one, at least relative to the previous ones (I also know that the previous write is too bad, will continue to revise, blog also like software). At the beginning of this section we will see how the Windows app operates the files.

Read the file name, folder name on Windows

First we define a button and a TextBlock in XAML, and the process of reading the file/folder name is written in the Click event of the former, which is used to display the file information.

<Grid Background="{ThemeResource Applicationpagebackgroundthemebrush}">              <StackPanel Orientation="Horizontal">                          <button  Name  =< Span class= "Hljs-value" > "btngetname"  width  = " " height  =" + " content  =" read file name " click  = "Btngetname_click" />                           <TextBlock Name= "textblockfilename" Width=" Height" = " FontSize" = " a" Margin="/> "                   </StackPanel>         </Grid>

The following code first reads the picture library through the Storagefolder class and then asynchronously loads the file and folder information of the picture library into the corresponding list. Create a new StringBuilder to save these files, where only the Name property of the file/folder is used, but there are many properties, such as the Path property. Finally, the obtained information can be assigned to TextBlock.

        Private Async void Btngetname_click(Objectsender, RoutedEventArgs e) {Storagefolder picturefolder = knownfolders.pictureslibrary; Ireadonlylist<storagefile> picturefilelist =awaitPicturefolder.getfilesasync (); Ireadonlylist<storagefolder> picturefolderlist =awaitPicturefolder.getfoldersasync (); StringBuilder Picutrefolderinfo =NewStringBuilder ();foreach(StorageFile FinchPicturefilelist) {picutrefolderinfo.append (f.name+"\ n"); }foreach(Storagefolder FinchPicturefolderlist) {picutrefolderinfo.append (f.name+"\ n");                        } Textblockfilename.text = Picutrefolderinfo.tostring (); }

Note that you want to precede the method name with async. And to declare in the manifest file that our app wants to use the picture library. Oh, just like in the Windows Phone.

Read the file name, folder name on the Windows Phone

Background code does not have to make any changes, just modify the XAML code to fit the screen ~

<Grid>    <StackPanel Orientation="Vertical">         <button  Name  =< Span class= "Hljs-value" > "btngetname"  width  = " " height  =" all " horizontalalignment  = "Center"  content  = "read file name"   Click  = "Btngetname_click" />          <TextBlock Name="Textblockfilename" Width=" Height" = " FontSize" = " a" Margin=" textwrapping" = "Wrap"/>    </StackPanel>           </Grid>
Other ways to read file names
        Private Async void Btngetname_click(Objectsender, RoutedEventArgs e) {Storagefolder picuturefolder = knownfolders.pictureslibrary; StringBuilder Picturefolderinfo =NewStringBuilder (); Ireadonlylist<istorageitem> Picturefileitem =awaitPicuturefolder.getitemsasync ();foreach(varIinchPicturefileitem) {if(I isStoragefolder) Picturefolderinfo.append (I.name +"\ n");ElsePicturefolderinfo.append (I.name +"\ n");        } Textblockfilename.text = Picturefolderinfo.tostring (); }

"Miles Journey--windows App development" file operation--read file

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.