Friday, October 5, 2012

Storing files in DB in asp.net MVC

CSHTML
@using (Html.BeginForm("SaveFile", "MyController", FormMethod.Post, new { enctype = "multipart/form-data", id = "fileAjaxForm", autocomplete="off" }))
{

}

Controller
public JsonResult SaveFile(HttpPostedFileBase resumeFile)
{  
   if (resumeFile != null && resumeFile.ContentLength > 0)
   {
        int size = resumeFile.ContentLength;
        byte[] fileData = resumeFile.InputStream.Read(fileData, 0, size);
        DataAccess.SaveFileData(Path.GetFileName(resumeFile.FileName),resumeFile.ContentType, fileData)  
   }
}
DB
Field Name Type
FileName nvarchar(255)
Content Type nvarchar(255)
Content image

No comments:

Post a Comment