【发布时间】:2015-12-07 21:51:08
【问题描述】:
我需要将 CSV 文件上传到 Azure 服务器上的 ASP.NET 应用程序。虽然它在我的本地机器上运行良好,但在将其上传到服务器时会引发以下错误:
"进程无法访问文件 'C:\inetpub\wwwroot\ImportFiles\9_11.csv' 因为它被 另一个进程”
我的代码:
string fileName = DateTime.Now.ToString().Replace(':', '_').Replace('/', '_').Replace(' ', '_') + Convert.ToString((new Random()).Next(0, 999) * (new Random()).Next(0, 999));
string path = Server.MapPath("ImportFiles") + "\\" + fileName + "" + FileImport.FileName.Substring(FileImport.FileName.IndexOf('.'));
FileImport.SaveAs(path);
string pathforSeconStream = path;
try
{
Response.Write("<script> alert('In Try Block');</script>");
bool flag = true;
int visiblemessageCount = 0;
int rollNo = 1;
StreamReader ColLine = new StreamReader(path);
string ColInputline = ColLine.ReadLine();
String[] ColsInput = ColInputline.Split(',');
ColLine.Close();
ColLine.Dispose();
string preFix = "", RollNumber = "";
StreamReader sr = new StreamReader(pathforSeconStream);
}
catch(Exception ex)
{
}
【问题讨论】:
标签: c# asp.net excel streamreader data-import