在Windows Phone 8.1上保存文件

时间:2015-09-18 01:39:16

标签: c# windows-phone-8.1 filesavepicker

如何在Windows Phone 8.1上保存不替换以前文件的文件?因为使用下面的代码,总会有一个消息对话框来替换和取消,不能更改文件名。

这是代码:

public void Save()
        {
            //isContentChanged = false;
            FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; 
            //{
            //    SuggestedStartLocation = PickerLocationId.PicturesLibrary
            //};
            savePicker.FileTypeChoices.Add("Word Document", new List<string>() { ".docx" });
            savePicker.FileTypeChoices.Add("Word 97 - 2003 Document", new List<string>() { ".doc" });
            savePicker.FileTypeChoices.Add("Rich Text Document", new List<string>() { ".rtf" });
            savePicker.DefaultFileExtension = ".docx";
            savePicker.SuggestedFileName = "WordDocument";
            savePicker.PickSaveFileAndContinue();

        }

        /// <summary>
        /// Continues the file save picker.
        /// </summary>
        /// <param name="fileSavePickerContinuationEventArgs">The <see cref="FileSavePickerContinuationEventArgs"/> instance containing the event data.</param>
        public async void ContinueFileSavePicker(FileSavePickerContinuationEventArgs args)
        {
            bool showErrorMsg = false;
            if (args.File != null)
            {
                try
                {
                    System.Threading.CancellationTokenSource src = new System.Threading.CancellationTokenSource();
                    Debug.WriteLine(args.File.Name + " was saved.");
                    richTextBox.Save(args.File);
                }
                catch
                {
                    showErrorMsg = true;
                }
                if (showErrorMsg)
                {
                    MessageDialog dialog = new MessageDialog("Save Failed");
                    await dialog.ShowAsync();
                }
            }
        }

请帮帮我

0 个答案:

没有答案