本文整理匯總了C#中System.Web.HttpPostedFileBase.Where方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpPostedFileBase.Where方法的具體用法?C# HttpPostedFileBase.Where怎麽用?C# HttpPostedFileBase.Where使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Web.HttpPostedFileBase
的用法示例。
在下文中一共展示了HttpPostedFileBase.Where方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: New
public ActionResult New(Ad ad, HttpPostedFileBase[] images)
{
var manager = new SimpleAdManager(SimpleAds.Properties.Settings.Default.ConnectionString);
ad.Images = images.Where(i => i != null).Select(i =>
{
Guid g = Guid.NewGuid();
string fileName = g + ".jpg";
i.SaveAs(Server.MapPath("~/Uploads/" + fileName));
return fileName;
});
manager.AddAd(ad);
//3,6,10
List<string> adIds;
if (Request.Cookies["adIds"] != null)
{
adIds = Request.Cookies["adIds"].Value.Split(',').ToList();
}
else
{
adIds = new List<string>();
}
adIds.Add(ad.Id.ToString());
var cookie = new HttpCookie("adIds", String.Join(",", adIds));
Response.Cookies.Add(cookie);
return RedirectToAction("Index");
}
示例2: New
public ActionResult New(Ad ad, HttpPostedFileBase[] images)
{
var manager = new SimpleAdManager(Properties.Settings.Default.ConnectionString);
ad.Images = images.Where(i => i != null).Select(i =>
{
Guid g = Guid.NewGuid();
string fileName = g + ".jpg";
i.SaveAs(Server.MapPath("~/Uploads/" + fileName));
return fileName;
});
manager.AddAd(ad);
string ids;
if (Request.Cookies["adIds"] != null)
{
ids = Request.Cookies["adIds"].Value + "," + ad.Id;
}
else
{
ids = ad.Id.ToString();
}
var cookie = new HttpCookie("adIds", ids);
Response.Cookies.Add(cookie);
return RedirectToAction("Index");
}
示例3: Create
public ActionResult Create(HttpPostedFileBase[] uploadfile1, int idProp)
{
string myGuid;
var imagen = new Image();
if (uploadfile1 != null)
{
foreach (var file in uploadfile1.Where(x => x != null))
{
string extension = Path.GetExtension(file.FileName);
myGuid = Guid.NewGuid().ToString();
var rutaCompleta = Path.Combine(Server.MapPath("~/Images"), myGuid + extension);
file.SaveAs(rutaCompleta);
imagen.ImagenUrl = myGuid + extension;//se guarda SOLO el nombre de la imagen, ya se sabe que todas las img estan en la carpeta 'Images'
imagen.PropertyId = idProp;
db.Images.Add(imagen);
db.SaveChanges();
}
}
return View("Index","Home");//falta probarlo si redirecciona bien
}
示例4: Upload
public ActionResult Upload(HttpPostedFileBase[] upfile)
{
return View(upfile.Where(f => f != null));
}
示例5: ValidatePostedFiles
private void ValidatePostedFiles(HttpPostedFileBase[] files)
{
if (files != null && files.Count() > 0)
{
int maxFileSize = SiteConfig.MaxFileSize.ToInt();
List<string> invalidFileTypes = new List<string>();
bool uploadLimitExceeded = false;
foreach (var file in files.Where(item => item != null))
{
if (file.ContentLength > 0)
{
if (!_fileServices.ValidFileType(file.FileName))
invalidFileTypes.Add(System.IO.Path.GetExtension(file.FileName));
else if (file.ContentLength > maxFileSize * 1024)
uploadLimitExceeded = true;
}
}
string error = "";
if (uploadLimitExceeded)
error += "Max file size is " + maxFileSize + " kb.";
if (invalidFileTypes.Count > 0)
{
error += string.Format("File type not accepted ({0}).", string.Join(", ",invalidFileTypes));
}
if(!string.IsNullOrWhiteSpace(error))
ModelState.AddModelError("PostEditor.Files", error);
}
}