Jaimin Dave Jaimin Dave - 1 month ago 15
ASP.NET (C#) Question

Access to the path XXX is denied while uploading video in MVC

I have MVC application throwing error 'Access to path XXX denied' while uploading video. Error is not thrown when image is being uploaded.

Any thing wring in my code?

[HttpPost]
public ActionResult Index(HttpPostedFileBase video)
{
//var httpPostedFile = Request.Files[0];
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
//ffMpeg.GetVideoThumbnail(Server.MapPath("~/Images"), "video_thumbnail.jpg");

var fileName = Path.GetFileName(video.FileName);
var path = Server.MapPath("~/Images");
video.SaveAs(path);
ffMpeg.GetVideoThumbnail(path, "video_thumbnail.jpg");


return View();
}

Answer

Well, I would say you have a problem here

video.SaveAs(path);

as path doesn't contains file name (you try to save with the directory as "fileName").

So

var path = Server.MapPath("~/Images");
var fileName = Path.Combine(path, video.FileName);
video.SaveAs(fileName);
Comments