Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.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# Can';在ASP.NET中使用FileUpload读取CSV文件_C#_Asp.net_Csv_File Upload - Fatal编程技术网

C# Can';在ASP.NET中使用FileUpload读取CSV文件

C# Can';在ASP.NET中使用FileUpload读取CSV文件,c#,asp.net,csv,file-upload,C#,Asp.net,Csv,File Upload,在我的一个网页上,我放置了FileUpload1项目,我想在其中存储CSV文件,然后对其进行分析。但是我无法读入它,抛出了一个异常。似乎文件路径发生了变化(我在桌面上有文件存储,但它显示文件是在C:\Program Files(x86)\IIS Express中搜索的) protectedvoid按钮2\u单击(对象发送者,事件参数 { Write(“Jestem w petli file.hasfile”); if(FileUpload1.PostedFile!=null) { 字符串file

在我的一个网页上,我放置了FileUpload1项目,我想在其中存储CSV文件,然后对其进行分析。但是我无法读入它,抛出了一个异常。似乎文件路径发生了变化(我在桌面上有文件存储,但它显示文件是在C:\Program Files(x86)\IIS Express中搜索的)

protectedvoid按钮2\u单击(对象发送者,事件参数
{
Write(“Jestem w petli file.hasfile”);
if(FileUpload1.PostedFile!=null)
{
字符串filePath=FileUpload1.PostedFile.FileName;
StreamReader=新的StreamReader(文件路径);
string[]readLines=新字符串[7];
int dayOfWeek=0;
while(星期日<7)
{
做
{
string textLine=reader.ReadToEnd();
readLines[dayOfWeek]=文本行;
}
while(reader.Peek()!=-1);
dayOfWeek++;
}
对于(int i=0;i<7;i++)
{
生成数据(读线[i],i);
}
reader.Close();
}
对于(int i=0;i<7;i++)
{
TableRow tblRow=新建TableRow();
表1.新增行数(待定);
对于(int j=0;j<2;j++)
{
TableCell tCell=新的TableCell();
tCell.Text=位置sinwtr[i,j];
tblRow.Cells.Add(tCell);
}
}
}        
你能告诉我我做错了什么吗

提前感谢,,
Kokos

在读取文件之前必须先保存文件。请检查此处的示例字符串fileName=FileUpload1.fileName;字符串savePath=@“c:\temp\uploads\”savePath+=fileName;FileUpload1.SaveAs(savePath);表示找不到部分路径:“c:\temp\uploads\dupa.csv”a)c:\temp\uploads\真的存在吗?b) 您的IIS Express进程有权访问它吗?a)它存在,但没有写访问权限。谢谢b) 对。它是以管理员权限打开的。
protected void Button2_Click(object sender, EventArgs 
{


        Response.Write("Jestem w petli file.hasfile");
        if (FileUpload1.PostedFile != null)
        {
            string filePath = FileUpload1.PostedFile.FileName;
            StreamReader reader = new StreamReader(filePath);
            string[] readLines = new string[7];
            int dayOfWeek = 0;

            while (dayOfWeek < 7)
            {
                do
                {
                    string textLine = reader.ReadToEnd();
                    readLines[dayOfWeek] = textLine;                      
                }
                while (reader.Peek() != -1);

                dayOfWeek++;
            }

            for(int i = 0; i < 7; i++)
            {
                generateData(readLines[i], i);
            }
            reader.Close();
        }
        for(int i = 0; i < 7; i++)
        {
            TableRow tblRow = new TableRow();
            Table1.Rows.Add(tblRow);

            for (int j = 0; j < 2; j++)
            {
                TableCell tCell = new TableCell();
                tCell.Text = positionsInWtr[i, j];
                tblRow.Cells.Add(tCell);                
            }
        }
    }