我给用户一个字段,他可以上传任何
图像文件我想检查文件不
应该大于 350kb ....如何在 c#
HttpPostedFileBase file = Request.Files[0];
string mynewpath = Request.PhysicalApplicationPath + "Upload\\";
if (file.ContentLength > 0)
{
// here i want to check that if file size is more then 350kb then i will give error
string[] extarray = new string[] { "image/jpeg", "image/jpg","image/png", "image/gif" };
var isallowedfile = extarray.Contains(file.ContentType);
if (!isallowedfile)
{
ModelState.AddModelError("", "Only image files (.jpeg , .gif , .png ) are accepted, please browse a image file");
return View("SurveyOptions", model);
}
string filename = Guid.NewGuid() + Path.GetFileName(file.FileName);
file.SaveAs(mynewpath + filename);
}