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.