如果文件正在以指定路径中已经存在的名称上传,则显示错误。我想用新文件替换。我已经放置了错误和代码。请帮助替换现有图像。
错误:该进程无法访问文件“”,因为它正被另一个进程使用。
代码:
[HttpPost]
public ActionResult MyUpload(HttpPostedFileBase file)
{
string filePath = string.Empty;
string path = "C:\\";
string filePath = string.Empty;
try
{
if (file != null && file.ContentLength > 0)
{
filePath = path + file.FileName;
file.SaveAs(filePath);
file.InputStream.Dispose();
GC.Collect();
// other operations, where can occur an exception
// (because the uploaded file can have a bad content etc.)
}
}
catch (Exception e)
{
}
}