当前位置: 首页>>代码示例>>C#>>正文


C# Pickers.FileSavePicker类代码示例

本文整理汇总了C#中Windows.Storage.Pickers.FileSavePicker的典型用法代码示例。如果您正苦于以下问题:C# FileSavePicker类的具体用法?C# FileSavePicker怎么用?C# FileSavePicker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileSavePicker类属于Windows.Storage.Pickers命名空间,在下文中一共展示了FileSavePicker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ButtonCamera_Click

        private async void ButtonCamera_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();
            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(600, 600);

            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo != null)
            {
                BitmapImage bmp = new BitmapImage();
                IRandomAccessStream stream = await photo.
                                                   OpenAsync(FileAccessMode.Read);
                bmp.SetSource(stream);
                BBQImage.Source = bmp;

                FileSavePicker savePicker = new FileSavePicker();
                savePicker.FileTypeChoices.Add
                                      ("jpeg image", new List<string>() { ".jpeg" });

                savePicker.SuggestedFileName = "New picture";

                StorageFile savedFile = await savePicker.PickSaveFileAsync();

                (this.DataContext as BBQRecipeViewModel).imageSource = savedFile.Path;

                if (savedFile != null)
                {
                    await photo.MoveAndReplaceAsync(savedFile);
                }
            }
        }
开发者ID:cheahengsoon,项目名称:Windows10UWP-HandsOnLab,代码行数:32,代码来源:BBQRecipePage.xaml.cs

示例2: SaveLogFile

		private async Task SaveLogFile(string sourcePath, string suggestedFilename)
		{
			var picker = new FileSavePicker
			{
				SuggestedFileName = suggestedFilename,
				SuggestedStartLocation = PickerLocationId.DocumentsLibrary
			};
			picker.FileTypeChoices.Add("Plain Text", new[] { ".txt" });

			var file = await picker.PickSaveFileAsync();

			if (file != null)
			{
				byte[] bytes;

				if (!File.Exists(sourcePath))
				{
					bytes = new byte[0];
				}
				else
				{
					// This way, we can read the file at the same time as we are logging to it.
					using (var fs = File.Open(sourcePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))
					using (var reader = new BinaryReader(fs))
						bytes = reader.ReadBytesAndVerify((int)fs.Length);
				}

				await FileIO.WriteBytesAsync(file, bytes);
			}
		}
开发者ID:sandersaares,项目名称:mvvm-example,代码行数:30,代码来源:MainPage.xaml.cs

示例3: Save

        public async Task Save(string filename, string contentType, MemoryStream stream)
        {
            StorageFile storageFile = null;
            FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.Desktop;
            savePicker.SuggestedFileName = filename;
            switch (contentType)
            {
                case "application/msexcel":
                    savePicker.FileTypeChoices.Add("Excel Files", new List<string>() { ".xlsx", });
                    break;

                case "application/msword":
                    savePicker.FileTypeChoices.Add("Word Document", new List<string>() { ".docx" });
                    break;

                case "application/pdf":
                    savePicker.FileTypeChoices.Add("Adobe PDF Document", new List<string>() { ".pdf" });
                    break;
                case "application/html":
                    savePicker.FileTypeChoices.Add("HTML Files", new List<string>() { ".html" });
                    break;
            }
            storageFile = await savePicker.PickSaveFileAsync();

            using (Stream outStream = await storageFile.OpenStreamForWriteAsync())
            {
                outStream.Write(stream.ToArray(), 0, (int)stream.Length);
            }

            await Windows.System.Launcher.LaunchFileAsync(storageFile);
        }
开发者ID:IanLeatherbury,项目名称:tryfsharpforms,代码行数:32,代码来源:SaveWindows81.cs

示例4: Export

        public static async Task<SaveAllSpecies> Export()
        {

            FileSavePicker exportPicker = new FileSavePicker();

            exportPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            exportPicker.FileTypeChoices.Add("XML", new List<string>() { ".xml" });
            exportPicker.DefaultFileExtension = ".xml";
            exportPicker.SuggestedFileName = "SwarmsSaves";
            exportPicker.CommitButtonText = "Export";
            StorageFile file = await exportPicker.PickSaveFileAsync();
            if (null != file)
            {
                using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (Stream outputStream = stream.AsStreamForWrite())
                    {
                        XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                        xmlWriterSettings.Indent = true;
                        xmlWriterSettings.Encoding = new UTF8Encoding(false);
                        XmlSerializer serializer = new XmlSerializer(typeof(SaveAllSpecies));
                        var game = await SaveHelper.LoadGameFile("AllSaved");
                        using (XmlWriter xmlWriter = XmlWriter.Create(outputStream, xmlWriterSettings))
                        {
                            serializer.Serialize(xmlWriter, game);
                        }
                        await outputStream.FlushAsync();
                        return game;
                    }
                }
            }
            return null;
        }
开发者ID:kbo4sho,项目名称:Swarm,代码行数:33,代码来源:ImportExportHelper.cs

示例5: SaveButton_Click

        private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Rich Text", new List<string>() { ".rtf" });

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "New Document";

            StorageFile file = await savePicker.PickSaveFileAsync();
            if (file != null)
            {
                // Prevent updates to the remote version of the file until we 
                // finish making changes and call CompleteUpdatesAsync.
                CachedFileManager.DeferUpdates(file);
                // write to file
                using (Windows.Storage.Streams.IRandomAccessStream randAccStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                {
                    editor.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);
                }

                // Let Windows know that we're finished changing the file so the 
                // other app can update the remote version of the file.
                FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
                if (status != FileUpdateStatus.Complete)
                {
                    Windows.UI.Popups.MessageDialog errorBox =
                        new Windows.UI.Popups.MessageDialog("File " + file.Name + " couldn't be saved.");
                    await errorBox.ShowAsync();
                }
            }
        }
开发者ID:C-C-D-I,项目名称:Windows-universal-samples,代码行数:35,代码来源:RichEditBoxPage.xaml.cs

示例6: Save_Executed

 /// <summary>
 /// Creates a text file with XAML brushes for a list of named colors.
 /// </summary>
 private async void Save_Executed()
 {
     var savePicker = new FileSavePicker();
     savePicker.SuggestedStartLocation = PickerLocationId.Desktop;
     savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
     savePicker.DefaultFileExtension = ".txt";
     savePicker.SuggestedFileName = "ColorSwatchBrushes";
     StorageFile file = await savePicker.PickSaveFileAsync();
     if (null != file)
     {
         try
         {
             await FileIO.WriteLinesAsync(file, Palette.Select(color => color.AsXamlResource()));
             Toast.ShowInfo("File saved");
         }
         catch (Exception ex)
         {
             Log.Error(ex.Message);
             Toast.ShowError("Oops, something went wrong.");
         }
     }
     else
     {
         Toast.ShowWarning("Operation cancelled.");
     }
 }
开发者ID:XamlBrewer,项目名称:UWP-Adobe-Color-Swatch-to-XAML,代码行数:29,代码来源:MainPageViewModel.cs

示例7: save_Video

        private async void save_Video(object sender, RoutedEventArgs e)
        {
            // Adding try catch block in case of occurence of an exception
            try
            {
                // Creating object of FileSavePicker and adding few values to the properties of the object.
                FileSavePicker fs = new FileSavePicker();
                fs.FileTypeChoices.Add("Video", new List<string>() { ".mp4",".3gp" });
                fs.DefaultFileExtension = ".mp4";
                fs.SuggestedFileName = "Video" + DateTime.Today.ToString();
                fs.SuggestedStartLocation = PickerLocationId.VideosLibrary;

                // Using storagefile object defined earlier in above method to save the file using filesavepicker.
                fs.SuggestedSaveFile = sf;

                // Saving the file
                var s = await fs.PickSaveFileAsync();
                if (s != null)
                {
                    using (var dataReader = new DataReader(rs.GetInputStreamAt(0)))
                    {
                        await dataReader.LoadAsync((uint)rs.Size);
                        byte[] buffer = new byte[(int)rs.Size];
                        dataReader.ReadBytes(buffer);
                        await FileIO.WriteBytesAsync(s, buffer);
                    }
                }
            }
            catch (Exception ex)
            {
                var messageDialog = new MessageDialog("Something went wrong.");
                await messageDialog.ShowAsync();
            }
        }
开发者ID:sarthakbhol,项目名称:Windows10AppSamples,代码行数:34,代码来源:MainPage.xaml.cs

示例8: SaveStreamToImage

        public static async Task<FileUpdateStatus> SaveStreamToImage(PickerLocationId location, string fileName, Stream stream, int pixelWidth, int pixelHeight)
        {
            var savePicker = new FileSavePicker
            {
                SuggestedStartLocation = location
            };
            savePicker.FileTypeChoices.Add("Png Image", new[] { ".png" });
            savePicker.SuggestedFileName = fileName;
            StorageFile sFile = await savePicker.PickSaveFileAsync();
            if (sFile != null)
            {
                CachedFileManager.DeferUpdates(sFile);

                using (var fileStream = await sFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var localDpi = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;

                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
                    Stream pixelStream = stream;
                    byte[] pixels = new byte[pixelStream.Length];
                    await pixelStream.ReadAsync(pixels, 0, pixels.Length);
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight,
                              (uint)pixelWidth,
                              (uint)pixelHeight,
                              localDpi,
                              localDpi,
                              pixels);
                    await encoder.FlushAsync();
                }

                FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(sFile);
                return status;
            }
            return FileUpdateStatus.Failed;
        }
开发者ID:EdiWang,项目名称:UWP-CharacterMap,代码行数:35,代码来源:Utils.cs

示例9: Save_File

        public async static void Save_File(SimpleCollada data)
        {
            FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("DAE", new List<string>() { ".dae" });
            savePicker.FileTypeChoices.Add("Xml", new List<string>() { ".xml" });
            
            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "Test";

            StorageFile file = await savePicker.PickSaveFileAsync();
            if (file != null)
            {
                IRandomAccessStream sessionRandomAccess = await file.OpenAsync(FileAccessMode.ReadWrite);
                IOutputStream sessionOutputStream = sessionRandomAccess.GetOutputStreamAt(0);
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(SimpleCollada));
                    serializer.Serialize(sessionOutputStream.AsStreamForWrite(), data);
                }
                catch (System.InvalidOperationException e)
                {
                    Debug.WriteLine(e.InnerException);
                }
                sessionRandomAccess.Dispose();
                await sessionOutputStream.FlushAsync();
                sessionOutputStream.Dispose();
            }
        }
开发者ID:dolkensp,项目名称:OTWB,代码行数:30,代码来源:SimpleCollada.cs

示例10: SaveTheForest

        async void SaveTheForest()
        {
            var displayInformation = DisplayInformation.GetForCurrentView();
            var imageSize = new Size(ACTWIDTH, ACTHEIGHT);
            canvasOfAvaga.Measure(imageSize);
            canvasOfAvaga.UpdateLayout();
            canvasOfAvaga.Arrange(new Rect(0, 0, imageSize.Width, imageSize.Height));

            var renderTargetBitmap = new RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(canvasOfAvaga, Convert.ToInt32(imageSize.Width), Convert.ToInt32(imageSize.Height));
            //await renderTargetBitmap.RenderAsync(canvasOfAvaga, Convert.ToInt32(ACTWIDTH), Convert.ToInt32(ACTHEIGHT));

            var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
            var picker = new FileSavePicker();
            picker.FileTypeChoices.Add(".jpg",new[] {".jpg"});
            var file = picker.PickSaveFileAsync();
            //var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("D:\\Screen.jpg", CreationCollisionOption.ReplaceExisting);
            using (var fileStream = await (await picker.PickSaveFileAsync()).OpenAsync(FileAccessMode.ReadWrite))
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, fileStream);

                encoder.SetPixelData(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Ignore,
                        (uint)renderTargetBitmap.PixelWidth,
                        (uint)renderTargetBitmap.PixelHeight,
                        displayInformation.LogicalDpi,
                        displayInformation.LogicalDpi,
                        pixelBuffer.ToArray());

                await encoder.FlushAsync();
            }
        }
开发者ID:tangopi,项目名称:Watamak,代码行数:33,代码来源:MainPage.xaml.cs

示例11: SaveFileButton_Click

        private async void SaveFileButton_Click(object sender, RoutedEventArgs e)
        {
            // Clear previous returned file name, if it exists, between iterations of this scenario
            OutputTextBlock.Text = "";

            FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "New Document";
            StorageFile file = await savePicker.PickSaveFileAsync();
            if (file != null)
            {
                // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
                CachedFileManager.DeferUpdates(file);
                // write to file
                await FileIO.WriteTextAsync(file, file.Name);
                // Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
                // Completing updates may require Windows to ask for user input.
                FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
                if (status == FileUpdateStatus.Complete)
                {
                    OutputTextBlock.Text = "File " + file.Name + " was saved.";
                }
                else
                {
                    OutputTextBlock.Text = "File " + file.Name + " couldn't be saved.";
                }
            }
            else
            {
                OutputTextBlock.Text = "Operation cancelled.";
            }
        }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:35,代码来源:Scenario4_SaveFile.xaml.cs

示例12: SaveToPngImage

        public static async Task<FileUpdateStatus> SaveToPngImage(this WriteableBitmap bitmap, PickerLocationId location, string fileName)
        {
            var savePicker = new FileSavePicker
            {
                SuggestedStartLocation = location
            };
            savePicker.FileTypeChoices.Add("Png Image", new[] { ".png" });
            savePicker.SuggestedFileName = fileName;
            StorageFile sFile = await savePicker.PickSaveFileAsync();
            if (sFile != null)
            {
                CachedFileManager.DeferUpdates(sFile);

                using (var fileStream = await sFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
                    Stream pixelStream = bitmap.PixelBuffer.AsStream();
                    byte[] pixels = new byte[pixelStream.Length];
                    await pixelStream.ReadAsync(pixels, 0, pixels.Length);
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
                              (uint)bitmap.PixelWidth,
                              (uint)bitmap.PixelHeight,
                              96.0,
                              96.0,
                              pixels);
                    await encoder.FlushAsync();
                }

                FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(sFile);
                return status;
            }
            return FileUpdateStatus.Failed;
        }
开发者ID:Autumn05,项目名称:UWP-Helpers,代码行数:33,代码来源:BitmapExtensions.cs

示例13: Save

        public async Task Save(Document document)
        {
            var doc = (LocalDocument)document;
            if (!doc.IsModified)
                return;

            StorageFile file;
            if (doc.File == null)
            {
                var filepicker = new FileSavePicker
                    {
                        DefaultFileExtension = ".md",
                        CommitButtonText = "Save",
                        SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                    };
                filepicker.FileTypeChoices.Add("Markdown", new List<string> { ".md", ".mdown", ".markdown", ".mkd" });
                file = await filepicker.PickSaveFileAsync();
                doc.File = file;

                string token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
                doc.Token = token;
                _localSettings.Values[file.Name] = token;
            }
            else
                file = doc.File;

            if (file != null)
            {
                doc.Name = file.Name;
                await FileIO.WriteTextAsync(file, doc.Text);
                doc.OriginalText = doc.Text.Trim('\r', '\n');
            }
        }
开发者ID:modulexcite,项目名称:MarkPadRT,代码行数:33,代码来源:LocalSource.cs

示例14: sButton_Click

        /// <summary>
        /// Preserves state associated with this page in case the application is suspended or the
        /// page is discarded from the navigation cache.  Values must conform to the serialization
        /// requirements of <see cref="SuspensionManager.SessionState"/>.
        /// </summary>
        /// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
       

        private async void sButton_Click(object sender, RoutedEventArgs e)
        {
        //    string x = nameInput.Text;

        //   StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
        //    StorageFile sampleFile = await storageFolder.CreateFileAsync(x);
       
           if (EnsureUnsnapped())
           {
                FileSavePicker savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                // Dropdown of file types the user can save the file as
                savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
                savePicker.FileTypeChoices.Add("Java Source File", new List<string>() { ".java" });
                savePicker.FileTypeChoices.Add("C++ Source File", new List<string>() { ".cpp" });
                // Default file name if the user does not type one in or select a file to replace
                savePicker.SuggestedFileName = "New Document";

                IAsyncOperation<StorageFile> asyncOp = savePicker.PickSaveFileAsync();
                StorageFile file = await asyncOp;
                if (this.Frame != null || file != null)
                {
                    this.Frame.Navigate(typeof(CodeEditor));
                }
           }

           


        }
开发者ID:blam77,项目名称:colorcode,代码行数:38,代码来源:MainPage.xaml.cs

示例15: Save

 /// <summary>
 /// 保存文件
 /// </summary>
 /// <param name="url"></param>
 /// <param name="savedPath"></param>
 /// <returns></returns>
 public static async Task<bool> Save(string url, string savedPath = null)
 {
     var uri = new Uri(url);
     var bytes = await uri.GetBytesFromUri();
     var extension = IsGif(bytes) ? ".gif" : ".jpg";
     string text = DateTime.Now.Ticks + extension;
     StorageFile storageFile = null;
     if (savedPath == null)
     {
         FileSavePicker fileSavePicker = new FileSavePicker();
         fileSavePicker.FileTypeChoices.Add("image", new List<string> { extension });
         fileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
         fileSavePicker.SuggestedFileName = text;
         storageFile = await fileSavePicker.PickSaveFileAsync();
     }
     else
     {
         StorageFolder storageFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync(savedPath, CreationCollisionOption.OpenIfExists);
         storageFile = await storageFolder.CreateFileAsync(text, CreationCollisionOption.ReplaceExisting);
     }
     if (storageFile == null)
     {
         return false;
     }
     await FileIO.WriteBytesAsync(storageFile, bytes);
     return true;
 }
开发者ID:chenrensong,项目名称:ImageLib.UWP,代码行数:33,代码来源:ImageHelper.cs


注:本文中的Windows.Storage.Pickers.FileSavePicker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。