35.winform之保存对话框

效果

35.winform之保存对话框

实现

35.winform之保存对话框
35.winform之保存对话框
35.winform之保存对话框

代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp5 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Title = "请选择要保存的路径";
            saveFileDialog.InitialDirectory = @"C:\Users\22053\Desktop";
            saveFileDialog.Filter = "文本文件|*.txt|所有文件|*.*";

            saveFileDialog.ShowDialog();

            //获得保存文件的路径
            string path = saveFileDialog.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("保存成功");
        }
    }
}

35.winform之保存对话框

上一篇:JENKINS针对不同项目组对用户进行权限分配


下一篇:C# remove single quotes from string