本文整理汇总了C#中System.Windows.Forms.SaveFileDialog.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# SaveFileDialog.OpenFile方法的具体用法?C# SaveFileDialog.OpenFile怎么用?C# SaveFileDialog.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.SaveFileDialog
的用法示例。
在下文中一共展示了SaveFileDialog.OpenFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportToTxt
public void ExportToTxt(DataView dv)
{
string fn = "bf" + Common.ChineseToSpell.GetChineseSpell(cmbLb.SelectedValue.ToString()).ToLower();//此处把值转换为拼音
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt(*.txt)|*.txt";
saveFileDialog1.FilterIndex = 0;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.CreatePrompt = true;
saveFileDialog1.Title = "导出txt文件到 ";
DateTime now = DateTime.Now;
saveFileDialog1.FileName = fn;
saveFileDialog1.ShowDialog();
Stream myStream;
myStream = saveFileDialog1.OpenFile();
StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
for (int rowNo = 0; rowNo < dv.Count; rowNo++)
{
String tempstr = "";
for (int columnNo = 0; columnNo < dv.Table.Columns.Count; columnNo++)
{
if (columnNo > 0)
{
tempstr += "\t ";
}
tempstr += dv.Table.Rows[rowNo][columnNo].ToString();
}
sw.WriteLine(tempstr);
}
sw.Close();
myStream.Close();
}
示例2: btn_FileSave_Click
private void btn_FileSave_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Title = "파일 저장 대화상자 예제";
dlg.CreatePrompt = true;
dlg.OverwritePrompt = true;
dlg.FileName = "default";
dlg.DefaultExt = "rtf";
dlg.InitialDirectory = "c:\\";
dlg.Filter = "RichText files (*.rtf)|*.rtf";
System.IO.MemoryStream memstream = new System.IO.MemoryStream();
this.richTextBox1.SaveFile(memstream, RichTextBoxStreamType.RichText);
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
System.IO.Stream fs = dlg.OpenFile();
memstream.Position = 0;
memstream.WriteTo(fs);
fs.Close();
this.textBox1.Text = dlg.FileName + " [[파일저장]]";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
示例3: cSVToolStripMenuItem_Click
private void cSVToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "workhistory.csv";
sfd.InitialDirectory = @"C:\";
sfd.Title = "保存先のファイルを選択してください";
sfd.RestoreDirectory = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
System.IO.Stream stream;
stream = sfd.OpenFile();
if (stream != null)
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(stream, new UTF8Encoding(true));
//header
sw.WriteLine("name, date, starttime, endtime, duration");
List<JobRecord> records = jobManager.GetAllJobRecords();
foreach (JobRecord record in records)
{
sw.WriteLine("{0},{1},{2},{3},{4}", record.name, record.date, record.startTime, record.endTime, record.duration);
}
sw.Close();
stream.Close();
}
}
}
示例4: SaveToFile
internal void SaveToFile()
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.AddExtension = true;
//sfd.CheckFileExists = true;
//sfd.CheckPathExists = true;
sfd.CreatePrompt = true;
sfd.DefaultExt = "rtf";
sfd.Filter = "リッチテキストフォーマット|*.rtf";
if (sfd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
Stream write = null;
try
{
write = sfd.OpenFile();
rtb_thread_main.SaveFile(write, RichTextBoxStreamType.RichText);
MessageBox.Show("セーブ成功しました。");
}
catch (System.IO.IOException)
{
MessageBox.Show("セーブ失敗ました。");
}
finally
{
if (write != null)
{
write.Close();
}
}
}
}
示例5: button_fileExport_Click
private void button_fileExport_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog ();
saveFileDialog.Filter = "CSV file|*.csv";
saveFileDialog.Title = "Export current view to CSV";
saveFileDialog.ShowDialog ();
if (saveFileDialog.FileName != string.Empty)
{
FileStream fs = (FileStream)saveFileDialog.OpenFile ();
try
{
CSVExporter.ExportCSV (dataManager.GetData (), fs);
}
catch (Exception ex)
{
Debug.WriteLine (ex.StackTrace);
}
finally
{
fs.Close ();
}
}
}
示例6: save
public void save()
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "WLD files (*.wld)|*.wld|All files (*.*)|*.*";
dialog.FileName = "S7PROG.wld";
dialog.FilterIndex = 1;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
System.IO.Stream fs;
if ((fs = dialog.OpenFile()) != null)
{
try
{
fs.Write(this.data.ToArray(), 0, this.data.Count);
}
catch
{
MessageBox.Show("Error saving file");
}
finally
{
fs.Close();
}
}
}
}
示例7: CommonExport
public void CommonExport()
{
DialogResult result = new DialogResult();
SaveFileDialog dialog = new SaveFileDialog();
dialog.RestoreDirectory = false;
dialog.Filter = "PNG Image (*.png) [Recommended]|*.png|JPEG Image (*.jpeg) [Bad Idea]|*.jpg|BMP Image (*.bmp)|*.bmp";
dialog.FileName = Path.ChangeExtension(filename, null);
dialog.AddExtension = true;
result = dialog.ShowDialog();
if (dialog.FileName != "" && result == DialogResult.OK)
{
System.IO.FileStream fs = (System.IO.FileStream)dialog.OpenFile();
switch (dialog.FilterIndex)
{
case 1:
bitmap.Save(fs,
System.Drawing.Imaging.ImageFormat.Png);
break;
case 2:
bitmap.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case 3:
bitmap.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;
}
fs.Close();
}
}
示例8: button2_Click
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "JPeg Imagen|*.jpg|Bitmap Imagen|*.bmp|PNG Imagen|*.png";
sfd.Title = "Guardar grafico en imagen";
sfd.ShowDialog();
if(sfd.FileName != "")
{
FileStream fs = (FileStream)sfd.OpenFile();
switch (sfd.FilterIndex)
{
case 1:
this.chart1.SaveImage(fs, ChartImageFormat.Jpeg);
break;
case 2:
this.chart1.SaveImage(fs, ChartImageFormat.Bmp);
break;
case 3:
this.chart1.SaveImage(fs, ChartImageFormat.Png);
break;
}
fs.Close();
}
}
示例9: saveGraphToFile
public bool saveGraphToFile(GraphClass graph)
{
// saving to user named file and user selected dir
Stream TestFileStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Graph file (*.gph)|*.gph";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((TestFileStream = saveFileDialog1.OpenFile()) != null)
{
BinaryFormatter serializer = new BinaryFormatter();
serializer.Serialize(TestFileStream, graph);
TestFileStream.Close();
}
else
{
return false;
}
}
return true;
}
示例10: BtnSave_Click
private void BtnSave_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Bitmap Image|*.bmp|JPEG Image|*.jpg";
dialog.Title = "Save Image";
dialog.ShowDialog();
if (dialog.FileName != "")
{
System.IO.FileStream fs = (System.IO.FileStream)dialog.OpenFile();
switch (dialog.FilterIndex)
{
case 1:
PBOutput.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case 2:
PBOutput.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
}
fs.Close();
}
}
示例11: buttonL_Click
private void buttonL_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog
{
Title = "保存L矩阵结果",
CheckPathExists = true,
InitialDirectory = @"E:\大学\大三下\摄影测量学\摄影测量学作业\Data",
Filter = "txt文件(*.txt)|*.txt"
};
if (sfd.ShowDialog() != DialogResult.OK) return;
using (StreamWriter sw = new StreamWriter(sfd.OpenFile(), Encoding.Default))
{
StringBuilder sb = new StringBuilder();
var data = _ro.FirstL.Data;
for (int i = 0; i < data.GetLength(0); i++)
{
for (int j = 0; j < data.GetLength(1); j++)
{
sb.Append(data[i, j] + "\t");
}
sb.Remove(sb.Length - 1, 1);
sb.AppendLine();
}
sw.Write(sb.ToString());
}
}
示例12: saveCollection_Click
private void saveCollection_Click(object sender, EventArgs e)
{
if (Interval.Text == "") { Interval.Text = "1"; }
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Filter = " | *.pix";
saveDialog.DefaultExt = "pix";
if (FileList.Items.Count == 0)
{
MessageBox.Show("No file names to save.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
if (openCollectionFileName == null)
saveDialog.FileName = null;
else
saveDialog.FileName = openCollectionFileName;
if (saveDialog.ShowDialog() == DialogResult.OK)
{
StreamWriter streamWriter = new StreamWriter(saveDialog.OpenFile());
foreach (string item in FileList.Items)
{
streamWriter.WriteLine(item);
}
streamWriter.Close();
}
}
示例13: myComputerToolStripMenuItem_Click
private void myComputerToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream myStream = null;
SaveFileDialog theDialog = new SaveFileDialog();
theDialog.Title = "Save Text File";
theDialog.Filter = "text files|*.txt";
theDialog.InitialDirectory = @"C:\";
if (theDialog.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = theDialog.OpenFile()) != null)
{
using (myStream)
{
// Insert code to read the stream here.
richTextBox1.SaveFile(myStream, RichTextBoxStreamType.PlainText);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
示例14: Main
static void Main(string[] args)
{
ConsoleColor old = Console.ForegroundColor;
try{
var props = new ConnectionProperties();
using (var frm = new ConnectionDialog(props, true, Assembly.LoadFrom))
{
var result = frm.ShowDialog();
if (result != System.Windows.Forms.DialogResult.OK)
return;
}
var cxi = new FakeConnection();
new ConnectionPropertiesSerializer().Serialize(cxi.DriverData, props);
var driver = new MongoDynamicDataContextDriver();
List<Assembly> assemblies = props.AssemblyLocations.Select(Assembly.LoadFrom).ToList();
var code = driver.GetStaticCodeFiles()
.Concat(new string[] {driver.GenerateDynamicCode(props, assemblies, "", "driver")});
if(props.InitializationQuery != null)
code = code.Concat(new string[]{driver.GenerateCustomInitQuery(props.InitializationQuery, "driver")});
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("------------------------------------------------");
foreach (string s in code)
{
Console.WriteLine(s);
Console.WriteLine("------------------------------------------------");
}
Console.ForegroundColor = old;
using (var frm = new SaveFileDialog())
{
var result = frm.ShowDialog();
if (result == DialogResult.OK)
{
using (StreamWriter writer = new StreamWriter(frm.OpenFile()))
{
foreach (string s in code)
{
writer.WriteLine(s);
writer.WriteLine("---------------------------------------------------");
}
writer.Flush();
}
}
}
}catch(Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex);
}
finally{
Console.ForegroundColor = old;
}
}
示例15: createFileToolStripMenuItem_Click
/// <summary>
/// Opens a file dialog that allows for creation of multiple databases
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void createFileToolStripMenuItem_Click (object sender, EventArgs e) {
Stream newFileStream;
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "SQLite files (*.sqlite)|*.sqlite";
saveFileDialog.FilterIndex = 2;
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == DialogResult.OK) {
if ((newFileStream = saveFileDialog.OpenFile()) != null) {
if (File.Exists(saveFileDialog.FileName)) {
newFileStream.Close();
DB = new SQLite.SQLiteConnection(saveFileDialog.FileName);
DB_Connection = saveFileDialog.FileName;
// Hard coded members class, need to add custom table structure
DB.CreateTable<Members>();
// Possibly save DB
SetView();
}
}
}
}