1

ファイルが指定されたパスに既にある名前でアップロードされている場合は、エラーが表示されています。新しいファイルに差し替えたい。エラーとコードを配置しました。既存の画像を置き換えるのを手伝ってください。

エラー: 別のプロセスで使用されているため、プロセスはファイル '' にアクセスできません。

コード:

[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)
    {
    }
}
4

2 に答える 2