Windows Phone 8.1 development: File selector Filesavepicker

Source: Internet
Author: User

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

Related Article

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.