[英]File.Delete cannot delete a file because it is being used by another process
I'm getting error when I'm overwriting the file. 覆盖文件时出现错误。 And if it is still working can't find to way for close file.
如果仍在工作,则无法找到关闭文件的方式。 Can someone help me please ?
有人能帮助我吗 ?
if (System.IO.File.Exists(Server.MapPath("/html/" + htmlname)))
{
System.IO.File.Delete(Server.MapPath("/html/" + htmlname));
System.IO.File.WriteAllText(Server.MapPath("/html/" + htmlname), mailbody);
}
else
{
System.IO.File.WriteAllText(Server.MapPath("/html/" + htmlname), mailbody);
}
Taken from msdn.com which is saying that : "The specified file is in use. -or- There is an open handle on the file, and the operating system is Windows XP or earlier. This open handle can result from enumerating directories and files. For more information, see How to: Enumerate Directories and Files." 摘自msdn.com,它表示:“指定的文件正在使用中。-或者-文件上有一个打开的句柄,并且操作系统是Windows XP或更早的版本。此打开的句柄可能由枚举目录和文件引起。有关更多信息,请参见如何:枚举目录和文件。
take a look a this : http://msdn.microsoft.com/en-us/library/system.io.file.delete.aspx 看一下这个: http : //msdn.microsoft.com/en-us/library/system.io.file.delete.aspx
Also doing some search on your own will prove to be efficient on the long run. 从长远来看,您也可以自己进行一些搜索。
Best regards. 最好的祝福。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.