[英]File.Delete cannot delete a file because it is being used by another process. Not sure how to fix this
[英]File.Delete cannot delete a file because it is being used by another process
覆蓋文件時出現錯誤。 如果仍在工作,則無法找到關閉文件的方式。 有人能幫助我嗎 ?
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);
}
摘自msdn.com,它表示:“指定的文件正在使用中。-或者-文件上有一個打開的句柄,並且操作系統是Windows XP或更早的版本。此打開的句柄可能由枚舉目錄和文件引起。有關更多信息,請參見如何:枚舉目錄和文件。
看一下這個: http : //msdn.microsoft.com/en-us/library/system.io.file.delete.aspx
從長遠來看,您也可以自己進行一些搜索。
最好的祝福。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.