I upload a file and check file exist with same name in target folder and delete if it exist. But the line I point above throws an exception with
"Cant access the file... because it is being used by another process"
message. Here is the code
public ActionResult Upload(int? chunk, string name)
{
string fileExtension = Path.GetExtension(name);
if (fileExtension != ".csv" && fileExtension != ".xml"){
return Json(new {
Success=false,
Message = "<b>Invalid file type</b>"
}, JsonRequestBehavior.AllowGet);
}
var fileUpload = Request.Files[0];
string fullName = Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data", fileUpload.FileName);
if (System.IO.File.Exists(fullName))
System.IO.File.Delete(fullName);// throws exception.
}