文件流操作,报“because it is being used by another process. ”错误解决

文件流操作,报“because it is being used by another process. ”错误解决

FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

将这句替换成:

using( FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
 {
 }
阅读更多

...because it is being used by anothr process求解!!!

04-11

最近用户不能访问站点,打开服务器一看,提示一个文本文件被一进程使用,无法访问。rn在网上查了资料,说是读取的流没有关闭,但我的关闭了的呀!rn而另一个站点采用了同一段代码,没有报过这样的错误!rn唯一不同的是,报错的站点,访问的用户在日本。但也是同一个集团的,在同一个网络内的。rnrn以下为两个站点的代码比较。rnrn[code=csharp] protected void Page_Load(object sender, EventArgs e)rn rn year = DateTime.Now.Year.ToString();rn DirectoryInfo dirWeeks = new DirectoryInfo(@"C:\Inetpub\wwwroot\ProductionPlan\" + year);rn weeks = dirWeeks.GetDirectories();rn selectedWeek = weeks[weeks.Length - 1].ToString().Substring(0, 2)+"W";//嵟岪堦廃rn lbWeek.Text = selectedWeek;//嵟岪堦廃rn if (!IsPostBack)rn rnrn // BindCombox(); rn WriteLog();rn InitLinkButton(); rn lbYear.Text = year; rn lbWeek.Text = selectedWeek;rn lbKind.Text = ddlPlan.SelectedValue; rn ;rn rn rnrn private void WriteLog()rn rn StreamWriter sw;rn System.IO.Directory.CreateDirectory(@"C:\Information");rn sw = File.AppendText(@"C:\Information\logPH.txt");rn IPHostEntry host = Dns.GetHostEntry(GetClientIP());rn string MyHost = host.HostName;rn // string Name=User.Identity.Name.ToString();rn sw.WriteLine("庡婘?崋丗" + MyHost + ",????丗" + DateTime.Now);rn //sw.WriteLine("庡婘?崋丗" + hname + ",梡?柤:" + Request.ServerVariables["LOGON_USER"] + "-----------" + DateTime.Now); rn // sw.WriteLine("梡?柤:" + Request.ServerVariables["LOGON_USER"] + ",????丗" + DateTime.Now); rn sw.Flush();rn sw.Close();rn rn private string GetClientIP()rn rn string result =rn HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];rn if (null == result || result == String.Empty)rn rn result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];rn rn if (null == result || result == String.Empty)rn rn result = HttpContext.Current.Request.UserHostName;rn rn return result;rn rn[/code]rnrn------------------------------------------------------------------rn[code=csharp]protected void Page_Load(object sender, EventArgs e)rn rn //string strhostname = System.Net.Dns.GetHostName();rn WriteLog();rn lbNotes.Text += GetMessage();rn rnrn private void WriteLog()rn rn StreamWriter sw;rn System.IO.Directory.CreateDirectory(@"C:\Information");rn sw=File.AppendText(@"C:\Information\log.txt"); rn IPHostEntry host= Dns.GetHostEntry(GetClientIP());rn string MyHost = host.HostName;rn // string Name=User.Identity.Name.ToString();rn sw.WriteLine("庡婘?崋丗" + MyHost + ",????丗" + DateTime.Now); rn //sw.WriteLine("庡婘?崋丗" + hname + ",梡?柤:" + Request.ServerVariables["LOGON_USER"] + "-----------" + DateTime.Now); rn // sw.WriteLine("梡?柤:" + Request.ServerVariables["LOGON_USER"] + ",????丗" + DateTime.Now); rn sw.Flush();rn sw.Close();rn rn private string GetClientIP()rn rn string result =rn HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];rn if (null == result || result == String.Empty)rn rn result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];rn rn if (null == result || result == String.Empty)rn rn result = HttpContext.Current.Request.UserHostName;rn rn return result;rn [/code]rn

没有更多推荐了,返回首页