【C#学习笔记】保存文件

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

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        string filename;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dig = new OpenFileDialog();
            if (dig.ShowDialog()==DialogResult.OK)
                filename = dig.FileName;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog dig = new SaveFileDialog();
            if (dig.ShowDialog()==DialogResult.OK)
                File.Copy(filename,dig.FileName);
        }
    }
}
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsFormsApplication5 { public partial class Form1 : Form { string filename; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog dig = new OpenFileDialog(); if (dig.ShowDialog()==DialogResult.OK) filename = dig.FileName; } private void button2_Click(object sender, EventArgs e) { SaveFileDialog dig = new SaveFileDialog(); if (dig.ShowDialog()==DialogResult.OK) File.Copy(filename,dig.FileName); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsFormsApplication5 { public partial class Form1 : Form { string filename; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog dig = new OpenFileDialog(); if (dig.ShowDialog()==DialogResult.OK) filename = dig.FileName; } private void button2_Click(object sender, EventArgs e) { SaveFileDialog dig = new SaveFileDialog(); if (dig.ShowDialog()==DialogResult.OK) File.Copy(filename,dig.FileName); } } }
经验分享 程序员 微信小程序 职场和发展