C# 打开文件对话框(OpenFileDialog)


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

namespace _06DataImport
{
    public partial class MainFrm : Form
    {
        public MainFrm()
        {
            InitializeComponent();
        }

        private void btnSelectDataFile_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "文本文件|*.txt";
                if (ofd.ShowDialog() == DialogResult.OK)  //如果点击的是打开文件
                {
                    this.txtFilePath.Text = ofd.FileName;  //获取全路径文件名

                    MessageBox.Show("OK");
                }
            }
        }
    }
}



你可能感兴趣的:(C#)