public ActionResult Upload(Guid id, HttpPostedFileBase file) { FilesRepository fr = new FilesRepository(); if (file != null) { byte[] readBytes = new byte[2]; file.InputStream.Read(readBytes, 0, 2); file.InputStream.Position = 0; /*if ( * (readBytes[0] == 80 & readBytes[1] == 75) || //zip * (readBytes[0] == 82 & readBytes[1] == 97) || //rar * (readBytes[0] == 137 & readBytes[1] == 80) || //png * (readBytes[0] == 105 & readBytes[1] == 115)//mp4 * ) * * {*/ if (file.ContentLength <= 104857600) { //string Path = Server.MapPath("//FileStorage") + "//" + newFilename; string name = Path.GetFileName(file.FileName); string path = Path.Combine(Server.MapPath("~/FileStorage") + "//" + name); file.SaveAs(path); ViewBag.Message = "File uploaded"; Upload u = new Upload(); u.File_id = id; u.Path = name; fr.AddUpload(u); ViewBag.Message = "File is uploaded successfully"; } else { ViewBag.Error = "File should be smaller than 2 GB"; } /*} * else ViewBag.Error = "File type not allowed";*/ } var fails = fr.GetFiles().SingleOrDefault(x => x.id == id); return(View(fails)); }