保存使用SaveFileDialog在C#文件 [英] Saving file using SaveFileDialog in C#

查看:121
本文介绍了保存使用SaveFileDialog在C#文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果任何人都可以帮我请。基本上,我使用 SAVEFILE
我试着读MSDN上的文档,但我很新的这,老实说我觉得他们有时不清楚。

I was wondering if anyone could help me please. Basically I'm using SaveFile, I tried reading the docs on MSDN but I'm very new to this and to be honest I find them sometimes unclear.

下面是我需要做的。

1)将文件保存到默认的C:,但可以这样做,如果它改名为不同的,我的机器的主要驱动器标为F上保存到主目录:,我怎么能直接节省如果改名?

1) Save the File to the default "C:", but can this be done to save to the main directory if it's renamed different, on my machine main drive is labelled F:, how could I direct the save if its renamed ?

2)是否有和选项设置让文件只能保存为二进制?并没有其他类型的?

2) Is there and option to set so file can only be saved as binary? and no other type?

任何帮助或指导将是巨大的,
谢谢大家提前!

Any help or guidance would be great, Thank you all in advance!

推荐答案

SaveFileDialog 控制不会做任何储蓄的。它所做的就是为您提供方便的接口,实际显示Windows的默认文件保存对话框。

The SaveFileDialog control won't do any saving at all. All it does is providing you a convenient interface to actually display Windows' default file save dialog.

1)设置属性 InitialDirectory 来驱动你想它表现出一些其他的默认。试想可能有不同的布局其他计算机。默认情况下Windows将保存目录上次使用的时间和present一遍。

1) Set the property InitialDirectory to the drive you'd like it to show some other default. Just think of other computers that might have a different layout. By default windows will save the directory used the last time and present it again.

2)即控制之外处理。你必须检查对话的结果,然后做自己节省(如写文本或二进制文件)。

2) That is handled outside the control. You'll have to check the dialog's results and then do the saving yourself (e.g. write a text or binary file).

就像一个简单的例子(有替代办法做到这一点)。
saveFile的是类型的控件 SaveFileDialog

Just as a quick example (there are alternative ways to do it). savefile is a control of type SaveFileDialog

SaveFileDialog savefile = new SaveFileDialog(); 
// set a default file name
savefile.FileName = "unknown.txt";
// set filters - this can be done in properties as well
savefile.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

if (savefile.ShowDialog() == DialogResult.OK)
{
    using (StreamWriter sw = new StreamWriter(savefile.FileName))
        sw.WriteLine ("Hello World!");
}

这篇关于保存使用SaveFileDialog在C#文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆