Windows 8 Store Apps Learning (25) Selector: File Selection window, etc.

Source: Internet
Author: User
Tags save file xmlns

Selector: File Selection window, folder Selection window, File Save window

Introduced

Re-imagine the Windows 8 Store Apps Selector

Fileopenpicker-Select a file or multiple files

Folderpicker-Select a folder

Filesavepicker-Save file to specified path

Example

1. Demonstrates how to select a file or multiple files by Fileopenpicker

Picker/fileopenpickerdemo.xaml

<page
    x:class= "XamlDemo.Picker.FileOpenPickerDemo"
    xmlns= "http://schemas.microsoft.com/winfx/2006/ Xaml/presentation "
    xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
    xmlns:local=" using: Xamldemo.picker "
    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= "Btnpickfile" content= "Pick a file" click= "Btnpickfile_click_1" margin= "0 0 0"/>
    
            < Button Name= "Btnpickfiles" content= "Pick Multiple Files" click= "Btnpickfiles_click_1" margin= "0 0 0"/> </
    
        stackpanel>
    </Grid>
</Page>

Picker/fileopenpickerdemo.xaml.cs

* * Demonstrates how to select a file or multiple files through Fileopenpicker * fileopenpicker-File Selection window * ViewMode-File Selection window view mode, Windows.Storage.Pick ERs. Pickerviewmode enumeration (List or Thumbnail) * suggestedstartlocation-the initial path displayed by the File Selection window, Windows.Storage.Pickers.PickerLocationI D enumeration * Documentslibrary, Computerfolder, Desktop,, Downloads, HomeGroup, Musiclibrary, PICTURESLIBRARY,VIDEOSLIBR ARY * Filetypefilter-allows display of the file type collection in the File Selection window * Commitbuttontext-the display text of the submit button for the File Selection window, which displays the text "open" by default * PICKSINGL
Efileasync ()-Pop-up File Selection window to allow users to select a file * Pickmultiplefilesasync ()-Pop-up File Selection window to allow users to select multiple files/using System;
Using System.Collections.Generic;
Using Windows.storage;
Using Windows.Storage.AccessCache;
Using Windows.Storage.Pickers;
Using Windows.UI.Xaml;
    
Using Windows.UI.Xaml.Controls; Namespace Xamldemo.picker {public sealed partial class Fileopenpickerdemo:page {public fileopenpickerd Emo () {this.
        InitializeComponent (); Private AsyNC void Btnpickfile_click_1 (object sender, RoutedEventArgs e) {if (XamlDemo.Common.Helper.EnsureUnsna
                Pped ()) {//Select a file Fileopenpicker openpicker = new Fileopenpicker ();
                Openpicker.commitbuttontext = "Select this file";
                Openpicker.viewmode = Pickerviewmode.thumbnail;
                Openpicker.suggestedstartlocation = pickerlocationid.pictureslibrary;
                OPENPICKER.FILETYPEFILTER.ADD (". jpg");
                OPENPICKER.FILETYPEFILTER.ADD (". gif");
    
                OPENPICKER.FILETYPEFILTER.ADD (". png"); Pop-up file Selection window Storagefile file = await openpicker.picksinglefileasync (); When the user completes the operation in the File Selection window, it returns the corresponding Storagefile object if (file!= null) {lblmsg. Text = "Selected files:" + file.
                Name;
                else {lblmsg.text = "canceled";
     }
            }   Private async void Btnpickfiles_click_1 (object sender, RoutedEventArgs e) {if (Xam  LDemo.Common.Helper.EnsureUnsnapped ()) {//Select multiple files Fileopenpicker openpicker =
                New Fileopenpicker ();
                Openpicker.viewmode = pickerviewmode.list;
                Openpicker.suggestedstartlocation = pickerlocationid.documentslibrary;
    
                OPENPICKER.FILETYPEFILTER.ADD ("*"); Pop-up file Selection window ireadonlylist<storagefile> files = await openpicker.pickmultiplefilesasync (); When the user completes the operation in the File Selection window, it returns the corresponding Storagefile object if (files).
                    Count > 0) {lblmsg.text = "selected file:";
                    Lblmsg.text + = Environment.NewLine; foreach (Storagefile file in files) {Lblmsg.text = = (file.
                        Name);
           Lblmsg.text + = Environment.NewLine;         } else {lblmsg.text = "canceled"; }
            }
        }
    }
}

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.