【发布时间】:2017-04-23 08:03:49
【问题描述】:
我无法在 chrome 中获取图像完整路径,但在 IE 中可以使用相同的代码。每当我从另一个位置选择图像时,它都会抛出错误
“System.IO.FileNotFoundException”类型的异常发生在 mscorlib.dll 中,但未在用户代码中处理 附加信息:找不到文件“C:\Program Files\IIS Express\Chrysanthemum.jpg”。
下面是我的Controller代码
public ActionResult Create([Bind(Include = "id,Name")] Employee employee, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
string Name = @"C:\temp\yourfile.png";
System.IO.File.WriteAllBytes(Name, System.IO.File.ReadAllBytes(file.FileName));
employee.image = System.IO.File.ReadAllBytes(file.FileName);
db.Employees.Add(employee);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(employee);
}
下面是我的MVC代码
<input type="file" name="file" id="file" />
<input type="submit" name="submitButton" value="Save" />
由于这个问题,我无法将图像保存在任何地方。 请帮我解决问题。
【问题讨论】:
标签: c# asp.net-mvc google-chrome file-io