16.WinForm练习--保存对话框

namespace _16.保存对话框
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

专业领域包括网站建设、成都网站制作、商城网站建设、微信营销、系统平台开发, 与其他网站设计及系统开发公司不同,创新互联建站的整合解决方案结合了帮做网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,为客户提供全网互联网整合方案。

    private void button1_Click(object sender, EventArgs e)
    {
        //打开保存对话框
        SaveFileDialog sfd = new SaveFileDialog();
        //设置对话框属性
        sfd.Title = "请选择保存文件的路径";
        sfd.InitialDirectory = @"C:\Users\Administrator.USER-20180925HC\Desktop\pic";
        sfd.Filter = "文本文件|*.txt|所有文件|*.*";
        sfd.ShowDialog();

        //获得保存文件的路径
        string path = sfd.FileName;
        if (path == "")
        {
            return;
        }
        using(FileStream fsWrite=new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
        {
            byte[] buffer = Encoding.Default.GetBytes(textBox1.Text);
            fsWrite.Write(buffer, 0, buffer.Length);
        }
        MessageBox.Show("保存成功");

    }
}

}


文章标题:16.WinForm练习--保存对话框
当前地址:http://csdahua.cn/article/igjsgc.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流