Windows 8 Store Apps Learning (22) file system: Accessing folders and files, searching local files

Source: Internet
Author: User
Tags expression file system list of attributes xmlns

File system: Accessing folders and files, searching for local files via Aqs

Introduced

Re-imagine the Windows 8 Store Apps File system

File access-access folders and files, and get various properties of files

Folder Access-some special actions when traversing folders

Thumbnail access-Get a thumbnail of a file

AQS-Search local files via Aqs (Advanced Query Syntax)

Example

1. Demonstrates how to access folders and files, and how to get the various properties of a file

Filesystem/fileaccess.xaml

<page
    x:class= "XamlDemo.FileSystem.FileAccess"
    xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation "
    xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
    xmlns:local=" using: Xamldemo.filesystem "
    xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
    xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "
    mc:ignorable=" D ">
    
    <grid background=" Transparent ">
        <stackpanel margin=" 0 0 0 ">
    
            <textblock name=" lblmsg "fontsize=" 14.667 "/>
             
            <listbox name= "ListBox" width= "height=" selectionchanged= "Listbox_selectionchanged_1" Horizontalalignment= "left" margin= "0 0 0"/>
                
        </StackPanel>
    </Grid>
</Page>

Filesystem/fileaccess.xaml.cs

* * Demonstrates how to access folders and files, and how to get various properties of a file * * Storagefolder-Folder Action class * Get folder-related properties, rename, Create ... * * * storagefile-File Operation class * Get file-related properties, rename, Create ..., take ..., Copy ..., move ..., Delete ..., Open ..., Replace ...
* * Note: The related classes in the WinRT about the storage operations are in the Windows.storage namespace * * using System;
Using System.Collections.Generic;
Using Windows.storage;
Using Windows.Storage.FileProperties;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Navigation;
    
Using System.Linq;
        Namespace Xamldemo.filesystem {public sealed partial class Fileaccess:page {public FileAccess () {this.
        InitializeComponent (); } protected async override void Onnavigatedto (NavigationEventArgs e) {//traverse all top-level in the document library directory
            File (the document library feature needs to be selected in package.appxmanifest) storagefolder storagefolder = knownfolders.documentslibrary; ireadonlylist<storagefile> files = await storagefolder.getfilesasync ();
            Listbox.itemssource = files. Select (P => p.name).
        ToList ();
            Private async void Listbox_selectionchanged_1 (object sender, SelectionChangedEventArgs e) {
            Gets the user-selected file string fileName = (string) Listbox.selecteditem;
            Storagefolder storagefolder = knownfolders.documentslibrary;
    
            Storagefile Storagefile = await storagefolder.getfileasync (fileName);
                Displays various properties of the file if (storagefile!= null) {Lblmsg.text = "Name:" + storagefile.name;
                Lblmsg.text + = Environment.NewLine;
                Lblmsg.text + = "FileType:" + storagefile.filetype;
    
                Lblmsg.text + = Environment.NewLine;
                Basicproperties basicproperties = await storagefile.getbasicpropertiesasync ();
                Lblmsg.text + = "Size:" + basicproperties.size;
                Lblmsg.text + = Environment.NewLine; Lblmsg.text = "DatemoDified: "+ basicproperties.datemodified;
    
                Lblmsg.text + = Environment.NewLine; * * Get various other attributes of the file * Detailed list of attributes see: Http://msdn.microsoft.com/en-us/library/windows/desktop/ff5
                21735 (v=vs.85). aspx */list<string> propertiesname = new list<string> ();
                Propertiesname.add ("system.dateaccessed");
                Propertiesname.add ("system.datecreated");
                Propertiesname.add ("System.fileowner"); idictionary<string, object> extraproperties = await StorageFile.Properties.RetrievePropertiesAsync (
    
                Propertiesname);
                Lblmsg.text + + "system.dateaccessed:" + extraproperties["system.dateaccessed"];
                Lblmsg.text + = Environment.NewLine;
                Lblmsg.text + + "system.datecreated:" + extraproperties["system.datecreated"];
                Lblmsg.text + = Environment.NewLine; Lblmsg.text = "SystEm.
            Fileowner: "+ extraproperties[" System.fileowner "]; }
        }
    }
}

2. Demonstrates some special operations when traversing a folder

Filesystem/folderaccess.xaml

<page
    x:class= "XamlDemo.FileSystem.FolderAccess"
    xmlns= "http://schemas.microsoft.com/winfx/2006/ Xaml/presentation "
    xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
    xmlns:local=" using: Xamldemo.filesystem "
    xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
    xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "
    mc:ignorable=" D ">
    
    <grid background=" Transparent ">
        <stackpanel margin=" 0 0 0 ">
    
            <textblock name=" lblmsg "fontsize=" 14.667 "/>
    
            <button name= "Btngroupfile" content= "group file" click= "Btngroupfile_click_1" margin= "0 0 0"/>
    
            < Button Name= "Btnprefetchapi" content= "Loading information from Prefetch" click= "btnprefetchapi_click_1" margin= "0 0 0"/>
                
        < /stackpanel>
    </Grid>
</Page>

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.