Save a file using the file picker
As far as I am concerned, I still like using the file picker very much, because I can use my own code to invoke the various frames of the system.
In this example, you first add a button and a TextBlock to the XAML, named Btnsavefile and Tblocksaveinfo, respectively. For this save file, this operation can be done easily in the Click event in the background.
Private Async void Btnsavefile_click(Objectsender, RoutedEventArgs e) {Filesavepicker saveFile =NewFilesavepicker (); Savefile.suggestedstartlocation = pickerlocationid.documentslibrary;//file type shown in drop-down listSAVEFILE.FILETYPECHOICES.ADD ("Batch File",Newlist<string> () {". bat"});//Default file nameSavefile.suggestedfilename ="SaveFile"; StorageFile file =awaitSavefile.picksavefileasync ();if(file!=NULL) {//block updates to files before the user finishes the change and calls CompleteupdatesasyncCachedfilemanager.deferupdates (file);stringFilecontent ="@echo off \ dir/s \ n Pause.";awaitFileio.writetextasync (file, filecontent);//When the change is complete, other applications can make changes to the file. Fileupdatestatus UpdateStatus =awaitCachedfilemanager.completeupdatesasync (file);if(Updatestatus==fileupdatestatus.complete) {tblocksaveinfo.text = file. Name +"It's been saved. "; }Else{tblocksaveinfo.text = file. Name +"the Save failed. "; } }Else{Tblocksaveinfo.text =the save operation was canceled. "; }}
Most of the content I have been added to the code by way of comments, as for the filecontent of the code in the end what the meaning, we try to know, I feel quite interesting. 3 Lines of code list all files and folders on the hard disk
If you have tried to open this bat file, have you found it interesting?
What's more, the code we've just written can be used directly on the Windows Phone without modification. My Lumia 638 has been brushed on the Windows 10 preview, so you can look at the new resource manager.
To open a file using the file picker
Similar to saving files with a file picker, the logic for opening files is almost the same. In this example, a button named Btnopenfile and a TextBlock named Tblockopeninfo are also defined in XAML.
Private Async void Btnopenfile_click(Objectsender, RoutedEventArgs e) {Fileopenpicker openFile =NewFileopenpicker (); Openfile.suggestedstartlocation = pickerlocationid.documentslibrary; Openfile.viewmode = pickerviewmode.list; OPENFILE.FILETYPEFILTER.ADD (". txt"); OPENFILE.FILETYPEFILTER.ADD (". docx"); OPENFILE.FILETYPEFILTER.ADD (". pptx");//Select a single fileStorageFile file =awaitOpenfile.picksinglefileasync ();if(File! =NULL) {Tblockopeninfo.text ="The file you selected is:"+ file. Name; }Else{Tblockopeninfo.text =The Open file operation was canceled. "; }//Select multiple files //ireadonlylist<storagefile> fileList = await openfile.pickmultiplefilesasync (); //stringbuilder fileopeninfo = new StringBuilder (); //if (filelist!=null) //{ //foreach (StorageFile f in fileList) // { //Fileopeninfo.append (f.name + "\ n"); // } //Tblockopeninfo.text = "The file you selected is:" + "\ n" + fileopeninfo.tostring (); //} //else //{ //Tblockopeninfo.text = "The Open file operation was canceled. "; //}}
I have also listed the code that selects multiple files, just uncomment them. Like ViewMode and Filetypefilter, look at the names. Heavy in practice.
On the phone is also generic, I tried, and successfully entered the resource manager, but did not open the file. It should be because of the preview version, this preview version of Office has been removed, it is estimated that the next version of the general version of the Office app will be added.
"Miles Journey--windows App development" File picker