Summary of selecting a Quick Start for Metro style app development

Source: Internet
Author: User

1. select a single file. filetypefilter. Add is the file type that can be accessed.

 
Private async void filepickerbtn_click (Object sender, routedeventargs e) {fileopenpicker = new fileopenpicker (); fileopenpicker. filetypefilter. add (". jpg "); fileopenpicker. filetypefilter. add (". JPEG "); fileopenpicker. filetypefilter. add (". PNG "); fileopenpicker. suggestedstartlocation = pickerlocationid. pictureslibrary; storagefile file = await fileopenpicker. picksinglefileasync (); If (F Ile! = NULL) {displaytextblock. Text = file. Name ;}}

2. Select multiple files and select any file type

Private async void filepickerbtn_click (Object sender, routedeventargs e) {fileopenpicker = new fileopenpicker (); fileopenpicker. filetypefilter. add ("*"); fileopenpicker. suggestedstartlocation = pickerlocationid. pictureslibrary; ireadonlylist <storagefile> files = await fileopenpicker. pickmultiplefilesasync (); If (files. count> 0) {foreach (storagefile file in files) {displaytextblock. text + = file. name + "\ n ";}}}

 

3. Select a folder

Private async void folderpickerbtn_click (Object sender, routedeventargs e) {If (ensureunsnapped () {folderpicker = new folderpicker (); folderpicker. suggestedstartlocation = pickerlocationid. desktop; folderpicker. filetypefilter. add ("*"); storagefolder = await folderpicker. picksinglefolderasync (); If (null! = Storagefolder) {displaytextblock. Text = storagefolder. Name ;}}}

Filepicker APIs cannot be used in snapped state

 
Bool ensureunsnapped () {// filepicker APIs cannot be used in the snapped state. Return (applicationview. value! = Applicationviewstate. Snapped) | applicationview. tryunsnap ());}

 

4. Save the file

 
Private async void savefilebtn_click (Object sender, routedeventargs e) {If (ensureunsnapped () {filesavepicker savepicker = new filesavepicker (); savepicker. suggestedstartlocation = pickerlocationid. desktop; savepicker. filetypechoices. add ("text", new list <string> (){". TXT "}); savepicker. filetypechoices. add ("word docment", new list <string> (){". docx ",". doc "}); savepicker. defaultfileextension = ". Txt"; savepicker. suggestedfilename = "new document"; storagefile = await savepicker. picksavefileasync (); If (null! = Storagefile) {displaytextblock. Text = storagefile. Name ;}}}

Select a file to save the file you want. Customize the file type and file name.

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.