zoukankan      html  css  js  c++  java
  • windows phone 8.1开发:文件选择器FileSavePicker

    上一篇文章小梦分享了文件选择器FileOpenPicker的用法,这篇文章我们继续分享FileSavePicker的用法,FileSavePicker的用法几乎和FileOpenPicker用法一模一样.唯一的区别就是在FileOpenPicker中是通过FileTypeFilter属性添家字符串元素的,但是在FileSavePicker中是向FileTypeChoices属性表示的集合中添加元素的.FileTypeChoices是字典类型,因此它的每一个元素都必须具有唯一的键名,对应的值是IList<string>类型.

    下面我们通过将textbox的内容存入一个txt文件来说明FileSavePicker的用法,过程和FileOpenPicker用法是一样的.

    就把代码依次贴出来了:

       private void saveButton_Click(object sender, RoutedEventArgs e)
            {
                FileSavePicker savePicker = new FileSavePicker();
    
                savePicker.FileTypeChoices.Add("TXT", new List<string>() { ".txt" });
    
                savePicker.SuggestedFileName = "小梦";
                savePicker.ContinuationData["Operation"] = "Save";
                savePicker.PickSaveFileAndContinue();
            }
    protected override void OnActivated(IActivatedEventArgs args)
            {
                    if (args is FileSavePickerContinuationEventArgs)
                {
                    Frame rootFrame = Window.Current.Content as Frame;
                    if (!rootFrame.Navigate(typeof(MainPage)))
                    {
                        throw new Exception("Failed to create target page");
                    }
    
                    var s = rootFrame.Content as MainPage;
                    s.SavePickerArgs = (FileSavePickerContinuationEventArgs)args;
    
                }
                Window.Current.Activate();
            }
    private FileSavePickerContinuationEventArgs savePickerArgs;
            public FileSavePickerContinuationEventArgs SavePickerArgs
            {
                get { return savePickerArgs; }
                set
                {
                    savePickerArgs = value;
                    ContinuFileSavePicker(savePickerArgs);
                }
            }
    
            private async void ContinuFileSavePicker(FileSavePickerContinuationEventArgs args)
            {
                if (args.ContinuationData["Operation"] as string == "Save" && args.File != null)
                {
                    StorageFile txtFile = args.File;
    
                  await   FileIO.WriteTextAsync(txtFile, this.text.Text.ToString(), Windows.Storage.Streams.UnicodeEncoding.Utf8);
    
                }
    
            }
  • 相关阅读:
    :Spring + axis2 开发 webservice
    log file parallel write 和 log buffer space p1 p2 p3
    log file sync p1 p2 p3
    :Apache FTPClient操作“卡死”问题的分析和解决
    :Apache FTPClient操作“卡死”问题的分析和解决
    org.apache.catalina.LifecycleException: Failed to start component
    一个简单的Tk界面(可以录入和查询)
    函数调用子函数,注意子函数的位置
    Perl 采集磁盘信息
    Perl 使用Frame(放置其他控件的地方)
  • 原文地址:https://www.cnblogs.com/xdoudou/p/3936954.html
Copyright © 2011-2022 走看看