C# 选择文件或文件夹简单的方法

2015-11-01 来源:网络 点击:115
C#选择文件
 
 
	   OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.InitialDirectory = "C://";
            fileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            fileDialog.FilterIndex = 1;
            fileDialog.RestoreDirectory = true;
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = fileDialog.FileName;
            }
 
 
 
C#选择文件夹
	    string path = "";
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            folderBrowserDialog.ShowNewFolderButton = false;
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                path = folderBrowserDialog.SelectedPath;
            }
            else
            {
            }
            this.textBox1.Text = path;

得到文件夹下文件目录
	string[] dataFiles = Directory.GetFiles(path);

转:http://blog.csdn.net/ytc666/article/details/5313952

网络
Tag:
分享: