我正在尝试查看文本文件,我是如何在dataGridView中上传的 我可以从文件夹上传文件我如何选择put我有这个错误当dataGridView应该查看它:访问路径被拒绝
这是我的代码
private void button9_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
//
// The user selected a folder and pressed the OK button.
// We print the number of files found.
//
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
string file = System.IO.Path.GetFullPath(folderBrowserDialog1.SelectedPath);
string[] textData = System.IO.File.ReadAllLines(file.ToString());
//textBox1.Text = folderBrowserDialog1.ToString();
string[] headers = textData[0].Split(',');
DataTable dataTable1 = new DataTable();
foreach (string header in headers)
dataTable1.Columns.Add(header, typeof(string), null);
for (int i = 1; i < textData.Length; i++)
dataTable1.Rows.Add(textData[i].Split(','));
//Set the DataSource of DataGridView to the DataTable
dataGridView1.DataSource = dataTable1;
}