C# HttpPostedFileBase.SaveAs()方法是否使文件保持打开状态?

C# HttpPostedFileBase.SaveAs()方法是否使文件保持打开状态?,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我正在使用以下方法将上载的文件保存到ASP.Net MVC应用程序中: public static void SaveFile(HttpPostedFileBase file, string relativePath) { string absolutePath = HttpContext.Current.Server.MapPath(relativePath); file.SaveAs(absolutePath); } 我使用以下方法删除该文件: pu

我正在使用以下方法将上载的文件保存到ASP.Net MVC应用程序中:

public static void SaveFile(HttpPostedFileBase file, string relativePath)
{
    string absolutePath = HttpContext.Current.Server.MapPath(relativePath);            
    file.SaveAs(absolutePath);
}
我使用以下方法删除该文件:

public static bool DeleteFile(string relativePath)
{
    string absolutePath = HttpContext.Current.Server.MapPath(relativePath);
    if (File.Exists(absolutePath))
    {
        File.Delete(absolutePath)                
        return true;                            
    }
    return false;
}
当我试图在上传文件后立即删除它时,它不能被删除<代码>文件。删除(绝对路径)锁定。重新启动iisexpress后,它将成功删除该文件。我使用
processexplorer
检查文件是否在任何其他应用程序中打开。它在iisexpress上是开放的。
HttpPostedFileBase.SaveAs()方法是否保持文件打开

编辑
我通过ajax调用调用这些方法。

-如果要立即删除文件,为什么要保存文件??而且我不认为
File.SaveAs
方法打开文件它只是将文件流保存到驱动器——你确定没有在其他地方打开临时文件吗?它是一个图像库。可能是用户上传了错误的图像,所以他想删除它。我不在代码的任何其他部分打开文件。我只是返回文件路径来查看上传的文件。我真的很抱歉问这个问题。正如@Anant dabi提到的,HttpPostedFileBase.SaveAs()不会打开该文件。该文件是用另一个我在调试时没有考虑的服务打开的。。经验使你变得完美…:)