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