本文整理汇总了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);
}
}
示例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);
}
}
}
示例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();
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
}
}
}
示例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);
}
}
}
示例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;
}
示例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";
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
}
示例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);
}
}
}