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


C# SaveFileDialog.OpenFile方法代码示例

本文整理汇总了C#中Microsoft.Win32.SaveFileDialog.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# SaveFileDialog.OpenFile方法的具体用法?C# SaveFileDialog.OpenFile怎么用?C# SaveFileDialog.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Win32.SaveFileDialog的用法示例。


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

示例1: ExportToFile

        public static void ExportToFile(BitmapSource graphBitmap)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();
            const int FilterIndexJpeg = 1;
            const int FilterIndexPng = 2;
            saveDialog.Filter = "JPEG|*.jpg|PNG|*.png";
            saveDialog.Title = "Save Graph As";
            saveDialog.AddExtension = true;
            saveDialog.ShowDialog();

            if (string.IsNullOrEmpty(saveDialog.FileName))
            {
                return;
            }

            using (FileStream fileStream = (FileStream)saveDialog.OpenFile())
            {
                BitmapEncoder bitmapEncoder;

                switch (saveDialog.FilterIndex)
                {
                    case FilterIndexJpeg:
                        bitmapEncoder = new JpegBitmapEncoder();
                        break;
                    case FilterIndexPng:
                        bitmapEncoder = new PngBitmapEncoder();
                        break;
                    default:
                        throw new ArgumentException("Invalid file save type");
                }

                bitmapEncoder.Frames.Add(BitmapFrame.Create(graphBitmap));
                bitmapEncoder.Save(fileStream);
            }
        }
开发者ID:jzajac2,项目名称:AllYourTexts,代码行数:35,代码来源:GraphExporter.cs

示例2: SaveDocument

        public static void SaveDocument(RadFlowDocument document, string selectedFromat)
        {
            IFormatProvider<RadFlowDocument> formatProvider = null;
            switch (selectedFromat)
            {
                case "Docx":
                    formatProvider = new DocxFormatProvider();
                    break;
                case "Rtf":
                    formatProvider = new RtfFormatProvider();
                    break;
                case "Txt":
                    formatProvider = new TxtFormatProvider();
                    break;
            }
            if (formatProvider == null)
            {
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                selectedFromat,
                formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }
            }
        }
开发者ID:Motaz-Al-Zoubi,项目名称:xaml-sdk,代码行数:34,代码来源:FileHelper.cs

示例3: SaveFile

 private void SaveFile(object sender, RoutedEventArgs args)
 {
     var saveFile = new SaveFileDialog();
     FileStream xamlFile = null;
     saveFile.Filter = "FlowDocument Files (*.xaml)|*.xaml|All Files (*.*)|*.*";
     if (saveFile.ShowDialog().HasValue)
     {
         try
         {
             xamlFile = saveFile.OpenFile() as FileStream;
         }
         catch (Exception e)
         {
             var error = "There was a opening the file:\n\n";
             error += saveFile.FileName;
             error += "\n\nException details:\n\n";
             error += e.Message;
             MessageBox.Show(error);
             return;
         }
         if (xamlFile == null) return;
         XamlWriter.Save(FlowDocRdr.Document, xamlFile);
         xamlFile.Close();
     }
 }
开发者ID:blinds52,项目名称:WPF-Samples,代码行数:25,代码来源:MainWindow.cs

示例4: ExportXlsx

        private void ExportXlsx(object sender, RoutedEventArgs e)
        {
            //export the combined PDF
            SaveFileDialog dialog = new SaveFileDialog()
            {
                DefaultExt = "xlsx",
                Filter = String.Format("Workbooks (*.{0})|*.{0}|All files (*.*)|*.*", "xlsx"),
                FilterIndex = 1
            };

            if (dialog.ShowDialog() == true)
            {
                //export the data from the two RadGridVies instances in separate documents
                Workbook playersDoc = this.playersGrid.ExportToWorkbook();
                Workbook clubsDoc = this.clubsGrid.ExportToWorkbook();

                //merge the second document into the first one
                Worksheet clonedSheet = playersDoc.Worksheets.Add();
                clonedSheet.CopyFrom(clubsDoc.Sheets[0] as Worksheet);

                using (Stream stream = dialog.OpenFile())
                {
                    new XlsxFormatProvider().Export(playersDoc, stream);
                }
            }
        }
开发者ID:Ramlanka7,项目名称:xaml-sdk,代码行数:26,代码来源:MainWindow.xaml.cs

示例5: ExportPivotToExcel

        public static void ExportPivotToExcel(RadPivotGrid pivot)
        {        
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.DefaultExt = "xlsx";
          //  dialog.Filter = "CSV files (*.csv)|*.csv |All Files (*.*) | *.*";

            var result = dialog.ShowDialog();
            if ((bool)result)
            {
                try
                {
                    using (var stream = dialog.OpenFile())
                    {
                        var workbook = GenerateWorkbook(pivot);

                      //  IWorkbookFormatProvider formatProvider = new CsvFormatProvider();
                        //formatProvider.Export(workbook, stream);
                        XlsxFormatProvider provider = new XlsxFormatProvider();
                        provider.Export(workbook, stream);
                    }
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
          
        }
开发者ID:syatin003,项目名称:Wpf,代码行数:28,代码来源:ExportToCSVService.cs

示例6: Export

        private void Export(object param)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*.{1}|{2} files|*.{3}", "Pdf", "pdf", "Text", "txt");

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    RadFixedDocument document = this.CreateDocument();
                    switch (dialog.FilterIndex)
                    {
                        case 1:
                            PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
                            pdfFormatProvider.Export(document, stream);
                            break;
                        case 2:
                            using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                            {
                                TextFormatProvider textFormatProvider = new TextFormatProvider();
                                writer.Write(textFormatProvider.Export(document));
                            }
                            break;
                    }
                }
            }
        }
开发者ID:netintellect,项目名称:PluralsightSpaJumpStartFinal,代码行数:27,代码来源:ExampleViewModel.cs

示例7: ExportPdf

        private void ExportPdf(object sender, RoutedEventArgs e)
        {
            //export the combined PDF
            SaveFileDialog dialog = new SaveFileDialog()
            {
                DefaultExt = "pdf",
                Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", "pdf", "Pdf"),
                FilterIndex = 1
            };

            if (dialog.ShowDialog() == true)
            {
                //export the data from the two RadGridVies instances in separate documents
                RadFixedDocument playersDoc = this.playersGrid.ExportToRadFixedDocument();
                RadFixedDocument clubsDoc = this.clubsGrid.ExportToRadFixedDocument();

                //merge the second document into the first one
                playersDoc.Merge(clubsDoc);

                using (Stream stream = dialog.OpenFile())
                {
                    new PdfFormatProvider().Export(playersDoc, stream);
                }
            }
        }
开发者ID:Ramlanka7,项目名称:xaml-sdk,代码行数:25,代码来源:MainWindow.xaml.cs

示例8: Button1_Click

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            var pageSize = this.pager.PageSize;
            var pageIndex = this.pager.PageIndex;

            this.pager.PageIndex = 0;
            this.pager.PageSize = 0;

            string extension = "xlsx";

            SaveFileDialog dialog = new SaveFileDialog()
            {
                DefaultExt = extension,
                Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
                FilterIndex = 1
            };

            if (dialog.ShowDialog() == true)
            {
                using (Stream stream = dialog.OpenFile())
                {
                    this.clubsGrid.ExportToXlsx(stream);
                }
            }

            this.pager.PageSize = pageSize;
            this.pager.PageIndex = pageIndex;
        }
开发者ID:CJMarsland,项目名称:xaml-sdk,代码行数:28,代码来源:MainWindow.xaml.cs

示例9: WriteFile

        public static string WriteFile(this SerialPort com)
        {
            Stream output = null;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = Environment.CurrentDirectory;
            saveFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            saveFileDialog.FilterIndex = 1;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.OverwritePrompt = false;

            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    if ((output = saveFileDialog.OpenFile()) != null)
                    {
                        using (StreamWriter sw = new StreamWriter(output))
                        {
                            int count = com.BytesToRead;
                            byte [] buffer = new byte [count];
                            com.Read(buffer, 0, count);
                            string text = ASCIIEncoding.ASCII.GetString(buffer, 0, count);
                            sw.Write(text);
                            return string.Format("File {0} is recorded:\n{1}\n", saveFileDialog.FileName, text);
                        }
                    }
                }
                catch (Exception ex)
                {
                    return "Error: Could not read file from disk. Original error: " + ex.Message;
                }
            }
            return "File isn`t selected.\n";
        }
开发者ID:rukpet,项目名称:COM-Port,代码行数:35,代码来源:COM_PortHelper.cs

示例10: SaveFile

        public Stream SaveFile(string defaultExtension, string filter)
        {
            var fd = new SaveFileDialog { DefaultExt = defaultExtension, Filter = filter };

            var result = fd.ShowDialog();

            return result != null && result.Value ? fd.OpenFile() : null;
        }
开发者ID:mikecole,项目名称:ChocolateyGUI,代码行数:8,代码来源:PersistenceService.cs

示例11: Export_Excel_Click

		private void Export_Excel_Click(object sender, RoutedEventArgs e)
		{
			SaveFileDialog dialog = new SaveFileDialog();
			dialog.DefaultExt = "*.xlsx";
			dialog.Filter = "Files(*.xlsx)|*.xlsx";
			if (!(bool)dialog.ShowDialog())
				return;
			Stream fileStream = dialog.OpenFile();
			radChart.ExportToExcelML(fileStream);
			fileStream.Close();
		}
开发者ID:JoelWeber,项目名称:xaml-sdk,代码行数:11,代码来源:MainWindow.xaml.cs

示例12: Save

 // save file to, return a read / write stream
 public static Stream Save()
 {
     SaveFileDialog fd = new SaveFileDialog();
     fd.InitialDirectory = Path.GetFullPath(initialDirectory);
     fd.Filter = filter;
     fd.FilterIndex = 1;
     fd.RestoreDirectory = false;
     if (fd.ShowDialog().GetValueOrDefault())
         return fd.OpenFile();
     else
         return null;
 }
开发者ID:kevinxw,项目名称:CIS681-Pr4,代码行数:13,代码来源:FileManager.cs

示例13: SaveAs

        public static void SaveAs(ObservableCollection<Achievement> achievements)
        {
            var saveDialog = new SaveFileDialog {Filter = "Data files (*.save)|*.save;"};
            var ok = saveDialog.ShowDialog();

            if (ok.Value != true) return;

            _currentFilePath = saveDialog.FileName;
            using (var fs = saveDialog.OpenFile())
            {
                var serializer = new XmlSerializer(achievements.GetType());
                serializer.Serialize(fs, achievements);
            }
        }
开发者ID:tiddan,项目名称:AchievementManager,代码行数:14,代码来源:DataStore.cs

示例14: SaveClients

 private void SaveClients(object sender, RoutedEventArgs e)
 {
     var saveFileDialog = new SaveFileDialog();
     saveFileDialog.Filter = "*.txt|*.txt";
     saveFileDialog.DefaultExt = "txt";
     if (saveFileDialog.ShowDialog() == true)
     {
         using (var stream = saveFileDialog.OpenFile())
         using (var writer = new StreamWriter(stream))
         {
             foreach (var client in clients)
             {
                 writer.WriteLine(client.Raw);
             }
         }
     }
 }
开发者ID:vgrigoriu,项目名称:RedisMonitor,代码行数:17,代码来源:MainWindow.xaml.cs

示例15: SaveFile

 public virtual void SaveFile(FileConfig config, Action<Stream> callback)
 {
     SaveFileDialog dialog = new SaveFileDialog();
     if (config == null) config = this.CreateDefaultConfig();
     dialog.FileName = config.FileName;
     dialog.Filter = config.Filter;
     dialog.Title = config.Title;
     if (dialog.ShowDialog(Application.Current.MainWindow) == true)
     {
         config.FileName = dialog.FileName;
         if (callback != null)
         {
             var stream = dialog.OpenFile();
             callback.Invoke(stream);
         }
     }
 }
开发者ID:denghejun,项目名称:music-app,代码行数:17,代码来源:DialogBase.cs


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