public ActionResult UploadFile(FileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } string extension = Path.GetExtension(model.File.FileName); if (!(extension == ".txt") && !(extension == ".doc") && !(extension == ".docx")) { ModelState.AddModelError("File", "Only .txt, .doc or .docx extension "); return(View(model)); } string fileName = model.File.FileName; byte[] data; using (Stream inputStream = model.File.InputStream) { MemoryStream memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } data = memoryStream.ToArray(); } var FileID = myDal.UploadFile(data, fileName); return(RedirectToAction("Index", "Home")); }