Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在dataGridView中查看上载文件_C#_Datagridview - Fatal编程技术网

C# 在dataGridView中查看上载文件

C# 在dataGridView中查看上载文件,c#,datagridview,C#,Datagridview,我正在尝试查看我在dataGridView中上载的文本文件 我可以从我选择的文件夹上传文件,当dataGridView应该查看时,我有这个错误:拒绝访问路径 这是我的密码 private void button9_Click(object sender, EventArgs e) { DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == Dial

我正在尝试查看我在dataGridView中上载的文本文件 我可以从我选择的文件夹上传文件,当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;

        }
private void按钮9\u单击(对象发送者,事件参数e)
{
DialogResult=folderBrowserDialog1.ShowDialog();
if(result==DialogResult.OK)
{
//
//用户选择了一个文件夹并按下了“确定”按钮。
//我们打印找到的文件数。
//
string[]files=Directory.GetFiles(folderBrowserDialog1.SelectedPath);
Show(“找到的文件:+Files.Length.ToString(),“Message”);
字符串文件=System.IO.Path.GetFullPath(folderBrowserDialog1.SelectedPath);
string[]textData=System.IO.File.ReadAllLines(File.ToString());
//textBox1.Text=folderBrowserDialog1.ToString();
字符串[]头=文本数据[0]。拆分(',');
DataTable dataTable1=新的DataTable();
foreach(标头中的字符串标头)
dataTable1.Columns.Add(header,typeof(string),null);
for(int i=1;i
您从哪里得到错误?我使用数组字符串来获取所有文件,当我试图获取文件字符串中的文件时,这是有效的,它们不会通过,并在这一行中给出错误字符串file=System.IO.Path.GetFullPath(folderBrowserDialog1.SelectedPath);