I have  a c# code that save a file to server and later will delete same file but i keeps on getting this error  the process cannot access the file because it is being used by another process. Please can anybody help me on how to dispose or close the file before deleting, Bellow is my code
var fileName = Path.GetFileName(UploadedFile.PostedFile.FileName); var filePath = Server.MapPath("/Content/uploads"); string savedFileName = Path.Combine(filePath, "ID" + fileName);
UploadedFile.PostedFile.SaveAs(savedFileName); UploadedFile.FileContent.Dispose(); if (System.IO.File.Exists(savedFileName)) {
System.IO.File.Delete(savedFileName);
}

Go to the complete details ...