本文整理汇总了C#中Microsoft.Win32.SaveFileDialog.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Win32.SaveFileDialog.OpenFile方法的具体用法?C# Microsoft.Win32.SaveFileDialog.OpenFile怎么用?C# Microsoft.Win32.SaveFileDialog.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.SaveFileDialog
的用法示例。
在下文中一共展示了Microsoft.Win32.SaveFileDialog.OpenFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
var dlg = new Microsoft.Win32.SaveFileDialog();
dlg.Filter = "PDF files (*.pdf)|*.pdf";
//var t = dlg.ShowDialog();
if (dlg.ShowDialog().Value)
{
// create pdf document
var pdf = new C1PdfDocument();
pdf.Landscape = true;
pdf.Compression = CompressionLevel.NoCompression;
// render all grids into pdf document
var options = new PdfExportOptions();
options.ScaleMode = ScaleMode.ActualSize;
GridExport.RenderGrid(pdf, _flex1, options);
pdf.NewPage();
GridExport.RenderGrid(pdf, _flex2, options);
pdf.NewPage();
GridExport.RenderGrid(pdf, _flex3, options);
pdf.NewPage();
GridExport.RenderGrid(pdf, _flex4, options);
// save document
using (var stream = dlg.OpenFile())
{
pdf.Save(stream);
}
}
}
示例2: Execute
public void Execute(ViewModel viewModel)
{
viewModel.Status = string.Empty;
var request = new ScanRequest()
{
DeviceId = viewModel.Scanner.Device.DeviceId,
Settings = new ScannerSettings
{
PageSize = PageSizes.Letter,
ColorDepth = ColorDepths.Color,
Orientation = Orientations.Portrait,
Resolution = Resolutions.R300,
UseAutomaticDocumentFeeder = true
}
};
IScanner proxy = DiscoveryHelper.CreateDiscoveryProxy();
try
{
var response = proxy.Scan(request);
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document";
dlg.DefaultExt = ".pdf";
dlg.Filter = "Acrobat|*.pdf";
var result = dlg.ShowDialog();
if (result == true)
{
using (var file = dlg.OpenFile())
{
CopyStream(response, file);
}
}
}
catch (FaultException<ScanError> e)
{
viewModel.Status = e.Detail.ErrorMessage;
}
catch (CommunicationException)
{
}
finally
{
ICommunicationObject comm = ((ICommunicationObject)proxy);
if (comm.State == CommunicationState.Faulted)
{
comm.Abort();
}
else
{
comm.Close();
}
}
}
示例3: ExportToImage
public static void ExportToImage(FrameworkElement surface)
{
Size size = new Size(surface.ActualWidth, surface.ActualHeight);
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32);
renderBitmap.Render(surface);
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = DateTime.Now.ToString("yyyy-M-d-H_m_s");
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\WLANFolder";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
dlg.InitialDirectory = path;
dlg.OverwritePrompt = true;
dlg.Filter = "JPEG Image|*.jpg|Bitmap Image|*.bmp|PNG Image|*.png";
dlg.Title = "Save an Image File";
dlg.ShowDialog();
dlg.RestoreDirectory = true;
if (dlg.FileName != "")
{
try
{
using(FileStream outStream = (System.IO.FileStream)dlg.OpenFile())
{
switch (dlg.FilterIndex)
{
case 1:
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(outStream);
}
break;
case 2:
{
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(outStream);
}
break;
case 3:
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
encoder.Save(outStream);
}
break;
default:
break;
}
System.Diagnostics.Process.Start(dlg.FileName);
}
}
catch (ArgumentException)
{ return; }
}
}
示例4: BtnStartClick
private void BtnStartClick(object sender, RoutedEventArgs e)
{
List<string> validEmails;
List<string> inValidEmails;
SeleniumDriver.Program.Run(_eMails, out validEmails, out inValidEmails);
// Configure save file dialog box
var dlg = new Microsoft.Win32.SaveFileDialog
{
FileName = "ValidEmails.txt",
Filter = "Text File | *.txt"
};
// Show save file dialog box
var result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
var writer = new StreamWriter(dlg.OpenFile());
foreach (var email in validEmails)
{
writer.WriteLine(email);
}
writer.Dispose();
writer.Close();
}
// Configure save file dialog box
dlg = new Microsoft.Win32.SaveFileDialog
{
FileName = "InValidEmails.txt",
Filter = "Text File | *.txt"
};
// Show save file dialog box
result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
var writer = new StreamWriter(dlg.OpenFile());
foreach (var email in inValidEmails)
{
writer.WriteLine(email);
}
writer.Dispose();
writer.Close();
}
}
示例5: GuardarComoMenuItem_Click
private void GuardarComoMenuItem_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.SaveFileDialog sdlg = new Microsoft.Win32.SaveFileDialog();
sdlg.Filter = "Text File (*.txt)|*.txt|Show All Files (*.*)|*.*";
sdlg.FileName = "Untitled";
sdlg.Title = "Save As";
Nullable<bool> result = sdlg.ShowDialog();
if (result == true)
{
using (var stream = sdlg.OpenFile())
{
var range = new TextRange(richTextBox1.Document.ContentStart,
richTextBox1.Document.ContentEnd);
range.Save(stream, DataFormats.Rtf);
}
}
}
示例6: Export
public static void Export(object columns, IEnumerable data, ExportType type = ExportType.Xls)
{
Microsoft.Win32.SaveFileDialog fileDialog = new Microsoft.Win32.SaveFileDialog();
fileDialog.Filter = type == ExportType.Xls ? "(*.xls)|*.xls" : "(*.*)|*.*";
fileDialog.FileName = "data_" + DateTime.Now.ToString("yyyyMMddHHmmss");
if (fileDialog.ShowDialog() == true)
{
using (var stream = fileDialog.OpenFile())
{
var cols = GetDataColumns(columns);
if (cols != null)
DoExport(stream, cols, data, type);
else
DoExport(stream, data, type);
}
//TODO: open the folder of the file
var dialog = new ExportResultDialog(fileDialog.FileName);
dialog.Owner = Window.GetWindow(Application.Current.MainWindow);
dialog.ShowDialog();
}
}
示例7: Save
public void Save(MemoryStream data, string FileName)
{
// the actionscript API will show the dialog after the user event
// has returned, so we must mimic it here
1.AtDelay(
delegate
{
var s = new Microsoft.Win32.SaveFileDialog();
s.FileName = FileName;
if (s.ShowDialog() ?? false)
{
using (var w = s.OpenFile())
{
var a = data.ToArray();
w.Write(a, 0, a.Length);
}
}
}
);
}
示例8: SaveClicked
private void SaveClicked(object sender, RoutedEventArgs e)
{
//
var dialog = new Microsoft.Win32.SaveFileDialog() { AddExtension = true };
dialog.Filter = "Portable Network Graphics|*.png";
bool? result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
try
{
using(Stream stream = dialog.OpenFile())
{
var encoder = new TiffBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapSource)this.image.Source));
encoder.Save(stream);
}
this.Close();
}
catch(SystemException ex)
{
MessageBox.Show("Can't save to the file. " + ex.Message, "File Error", MessageBoxButton.OK);
}
}
}
示例9: annotationCanvas_SaveAnnotation
void annotationCanvas_SaveAnnotation(Obany.Render.Objects.Canvas canvas, string mimeType)
{
_progressControl = new ProgressControl();
AddWatermark(canvas);
string files = CultureHelper.GetString(Properties.Resources.ResourceManager, "FILES");
string allFiles = CultureHelper.GetString(Properties.Resources.ResourceManager, "ALLFILES");
string ext = "";
string filter = "";
if (mimeType == "image/jpeg")
{
ext += ".jpg";
filter = "Jpg " + files + " (*.jpg)|*.jpg";
_progressControl.Status = CultureHelper.GetString(Properties.Resources.ResourceManager, "CREATING") + " Jpg";
}
else if (mimeType == "application/vnd.ms-xpsdocument")
{
ext += ".xps";
filter = "Xps " + files + " (*.xps)|*.xps";
_progressControl.Status = CultureHelper.GetString(Properties.Resources.ResourceManager, "CREATING") + " Xps";
}
else if (mimeType == "application/pdf")
{
ext += ".pdf";
filter = "Pdf " + files + " (*.pdf)|*.pdf";
_progressControl.Status = CultureHelper.GetString(Properties.Resources.ResourceManager, "CREATING") + " Pdf";
}
filter += "|" + allFiles + " (*.*)|*.*";
#if SILVERLIGHT
SaveFileDialog saveFileDialog = new SaveFileDialog();
#else
Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
if (!string.IsNullOrEmpty(_lastSavePath))
{
saveFileDialog.InitialDirectory = _lastSavePath;
}
#endif
saveFileDialog.DefaultExt = ext;
saveFileDialog.Filter = filter;
if (saveFileDialog.ShowDialog().Value)
{
#if !SILVERLIGHT
_lastSavePath = System.IO.Path.GetDirectoryName(saveFileDialog.FileName);
#endif
System.IO.Stream saveStream = saveFileDialog.OpenFile();
DialogPanel.ShowDialog(Properties.Resources.ResourceManager, "PROGRESS", _progressControl, "buttonCancel", DialogButtons.Cancel,
delegate(DialogResult dialogControlResult)
{
_progressControl = null;
}
);
_saveTaskId = Guid.NewGuid();
_coreLogic.AnnotationSave(_saveTaskId, saveStream, canvas, mimeType,
delegate(bool success, Guid saveTaskIdComplete)
{
Action a = delegate()
{
if (_saveTaskId == saveTaskIdComplete)
{
if (!success)
{
DialogPanel.ShowInformationBox(CultureHelper.GetString(Properties.Resources.ResourceManager, "ANNOTATIONUNABLETOSAVE"),
DialogButtons.Ok, null);
}
else
{
if (annotationCanvas != null)
{
annotationCanvas.ResetChanges();
}
}
if (_progressControl != null)
{
DialogPanel.Close(_progressControl, DialogResult.Close);
}
_saveTaskId = Guid.Empty;
}
};
#if SILVERLIGHT
Dispatcher.BeginInvoke(a);
#else
Dispatcher.Invoke(a);
#endif
});
}
}
示例10: button1_Click
//More tab save button
private void button1_Click(object sender, RoutedEventArgs e)
{
this.Cursor = Cursors.AppStarting;
button2.IsEnabled = false;
Microsoft.Win32.SaveFileDialog SaveFileDialog1 = new Microsoft.Win32.SaveFileDialog();
SaveFileDialog1.Filter = "txt files (*.txt)|*.txt";
if ((bool)SaveFileDialog1.ShowDialog())
{
using (System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(SaveFileDialog1.OpenFile()))
{
StreamWriter1.WriteLine("\n:::::::::::::::::{0}::::::::::::::::::", comboBox1.SelectedItem.ToString());
StreamWriter1.WriteLine(textBox5.Text);
StreamWriter1.Close();
}
MessageBox.Show("File saved successfully", "System Information", MessageBoxButton.OK, MessageBoxImage.Information);
}
this.Cursor = Cursors.Arrow;
button2.IsEnabled = true;
}
示例11: Save
protected virtual void Save(String path, Visifire.Charts.ExportType exportType, Boolean showDilog)
{
if (_saveIconImage != null)
{
_saveIconImage.Visibility = Visibility.Collapsed;
_toolTip.Hide();
_toolbarContainer.UpdateLayout();
}
#if SL
try
{
WriteableBitmap bitmap = new WriteableBitmap(this, null);
#if !WP
if (bitmap != null)
{
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.Filter = "JPEG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp";
saveDlg.DefaultExt = ".jpg";
if ((bool)saveDlg.ShowDialog())
{
using (Stream fs = saveDlg.OpenFile())
{
String[] filename = saveDlg.SafeFileName.Split('.');
String fileExt;
if (filename.Length >= 2)
{
fileExt = filename[filename.Length - 1];
exportType = (Visifire.Charts.ExportType)Enum.Parse(typeof(Visifire.Charts.ExportType), fileExt, true);
}
else
exportType = Visifire.Charts.ExportType.Jpg;
MemoryStream stream = Graphics.GetImageStream(bitmap, exportType);
// Get Bytes from memory stream and write into IO stream
byte[] binaryData = new Byte[stream.Length];
long bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
fs.Write(binaryData, 0, binaryData.Length);
}
}
}
#endif
}
catch (Exception ex)
{
if (_saveIconImage != null)
{
_saveIconImage.Visibility = Visibility.Visible;
}
System.Diagnostics.Debug.WriteLine("Note: Please make sure that Height and Width of the chart is set properly.");
System.Diagnostics.Debug.WriteLine(ex.Message);
}
#else
// Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
// double dx = m.M11* 96;
// double dy = m.M22 * 96;
// Save current canvas transform
Transform transform = this.LayoutTransform;
// reset current transform (in case it is scaled or rotated)
_rootElement.LayoutTransform = null;
// Create a render bitmap and push the surface to it
RenderTargetBitmap renderBitmap =
new RenderTargetBitmap(
(int)(this.ActualWidth),
(int)(this.ActualHeight),
96d,
96d,
PixelFormats.Pbgra32);
renderBitmap.Render(_rootElement);
if (showDilog)
{
Microsoft.Win32.SaveFileDialog saveDlg = new Microsoft.Win32.SaveFileDialog();
saveDlg.Filter = "Jpg Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp";
saveDlg.DefaultExt = ".jpg";
if ((bool)saveDlg.ShowDialog())
{
BitmapEncoder encoder;
if (saveDlg.FilterIndex == 2)
encoder = new BmpBitmapEncoder();
else
encoder = new JpegBitmapEncoder();
using (Stream fs = saveDlg.OpenFile())
{
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
// save the data to the stream
encoder.Save(fs);
}
}
}
//.........这里部分代码省略.........
示例12: OnExportMenuItemClick
private void OnExportMenuItemClick( object sender, RoutedEventArgs e )
{
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.Title = "Export Configuration";
AssignCommonFileDialogProps( dlg );
if( dlg.ShowDialog() != true ) return;
try
{
_windowData.Document.Save( dlg.OpenFile(), WidgetDocSaveFormat.Xml );
}
catch( Exception ex )
{
ReportToUserApplicationError( ex, "There were issues exporting configuration." );
}
}
示例13: Run
public override void Run(GraphController ctrl)
{
System.IO.Stream myStream;
var saveFileDialog1 = new Microsoft.Win32.SaveFileDialog();
saveFileDialog1.Filter = "Altaxo graph files (*.axogrp)|*.axogrp|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
if (true == saveFileDialog1.ShowDialog((System.Windows.Window)Current.Workbench.ViewObject))
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
info.BeginWriting(myStream);
info.AddValue("Graph", ctrl.Doc);
info.EndWriting();
myStream.Close();
}
}
}
示例14: Execute
public void Execute(object parameter)
{
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
sfd.OverwritePrompt = true;
sfd.CheckPathExists = true;
sfd.ValidateNames = true;
if (sfd.ShowDialog() != true) return;
using (System.IO.Stream s = sfd.OpenFile()) {
var list = vm.Rules.Where(x => x.Key < int.MaxValue - 1).Select(x => new Models.Data.Xml.XmlSerializableDictionary<int, ProxyRule>.LocalKeyValuePair(x.Key, x.Value)).ToList();
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(list.GetType());
xs.Serialize(s, list);
}
}
示例15: ExportToExcel
private void ExportToExcel()
{
//if (System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted)
//{
//MessageBox.Show("Due to restricted user-access permissions, this feature cannot be demonstrated when the Live Explorer is running as an XBAP browser application. Please download the full Xceed DataGrid for WPF package and run the Live Explorer as a desktop application to try out this feature.", "Feature unavailable");
//return;
//}
// The simplest way to export in Excel format is to call the
// DataGridControl.ExportToExcel() method. However, if you want to specify export
// settings, you have to take the longer, more descriptive and flexible route:
// the ExcelExporter class.
// excelExporter.FixedColumnCount will automatically be set to the specified
// grid's FixedColumnCount value.
//ExcelExporter excelExporter = new ExcelExporter(this.GridDetails);
//excelExporter.ExportStatFunctionsAsFormulas = this.exportStatFunctionsAsFormulasCheckBox.IsChecked.GetValueOrDefault();
//excelExporter.IncludeColumnHeaders = this.includeColumnHeadersCheckBox.IsChecked.GetValueOrDefault();
//excelExporter.IsHeaderFixed = this.isHeaderFixedCheckBox.IsChecked.GetValueOrDefault();
//excelExporter.RepeatParentData = this.repeatParentDataCheckBox.IsChecked.GetValueOrDefault();
//excelExporter.DetailDepth = Convert.ToInt32(this.detailDepthTextBox.Value);
//excelExporter.StatFunctionDepth = Convert.ToInt32(this.statFunctionDepthTextBox.Value);
//excelExporter.UseFieldNamesInHeader = this.UseFieldNamesInHeaderCheckBox.IsChecked.GetValueOrDefault();
Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
saveFileDialog.Filter = "XML Spreadsheet (*.xml)|*.xml|All files (*.*)|*.*";
try
{
if (saveFileDialog.ShowDialog().GetValueOrDefault())
{
using (Stream stream = saveFileDialog.OpenFile())
{
//excelExporter.Export(stream);
GridDetails.ExportToExcel(stream);
}
}
}
catch { }
}