Previous article small dream shared the use of file selector Fileopenpicker, this article we continue to share the use of Filesavepicker, The use of Filesavepicker is almost identical to that of Fileopenpicker. The only difference is that in Fileopenpicker, you add a home string element through the Filetypefilter attribute, However, in Filesavepicker, you add elements to the collection represented by the Filetypechoices property. Filetypechoices is a dictionary type, so every element of it must have a unique key name, and the corresponding value is ilist<string > type.
Below we explain the usage of filesavepicker by depositing the contents of the textbox into a TXT file, and the process and fileopenpicker usage are the same.
The code is pasted in turn:
Private voidsaveButton_Click (Objectsender, RoutedEventArgs e) {Filesavepicker Savepicker=NewFilesavepicker (); SAVEPICKER.FILETYPECHOICES.ADD ("TXT",Newlist<string> () {". txt" }); Savepicker.suggestedfilename="Little Dream"; savepicker.continuationdata["Operation"] ="Save"; Savepicker.picksavefileandcontinue (); }
protected Override voidOnActivated (Iactivatedeventargs args) {if(args isFilesavepickercontinuationeventargs) {Frame Rootframe= Window.Current.Content asFrame; if(!rootframe.navigate (typeof(MainPage))) { Throw NewException ("Failed to create target page"); } vars = rootframe.content asMainPage; S.savepickerargs=(Filesavepickercontinuationeventargs) args; } Window.Current.Activate (); }
PrivateFilesavepickercontinuationeventargs Savepickerargs; PublicFilesavepickercontinuationeventargs Savepickerargs {Get{returnSavepickerargs;} Set{Savepickerargs=value; Continufilesavepicker (Savepickerargs); } } Private Async voidContinufilesavepicker (Filesavepickercontinuationeventargs args) {if(args. continuationdata["Operation"] as string=="Save"&& args. File! =NULL) {StorageFile txtfile=args. File; awaitFileio.writetextasync (Txtfile, This. Text. Text.tostring (), Windows.Storage.Streams.UnicodeEncoding.Utf8); } }
Windows Phone 8.1 development: File selector Filesavepicker