Click here to Skip to main content
15,346,659 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to insert multi image here is my code but object reference error occur
----------------------------------------------
public ActionResult ProductSetup(IEnumerable<httppostedfilebase> files)
{
using (EcomShopingEntities Entities = new EcomShopingEntities())
{
ProImage_Shoping obj ;

Guid nimgGUID;

foreach (var file in files)
{
nimgGUID = Guid.NewGuid();
obj = new ProImage_Shoping();
obj.ProductId = 1;

if (!file.FileName.Trim().Equals(""))
{
string strExt = Path.GetExtension(file.FileName);

if (strExt.ToLower() == ".gif" || strExt.ToLower() == ".jpg" || strExt.ToLower() == ".png" || strExt.ToLower() == ".jpeg")
{
string ImgPath = Server.MapPath(ConfigurationManager.AppSettings.Get("product"));

ImgPath = ImgPath + "\\";

if (!System.IO.Directory.Exists(ImgPath))
{
System.IO.Directory.CreateDirectory(ImgPath);
}

ImgPath = ImgPath + "\\" + nimgGUID.ToString().Trim() + file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower();
file.SaveAs(ImgPath);
obj.ImageName = nimgGUID.ToString().Trim() + file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower();
obj.IsDeleted = false;
obj.CreatedBy = long.Parse(Session["UserId"].ToString());
obj.CreatedOn = DateTime.Now;
obj.ModifiedBy = obj.CreatedBy;
obj.ModifiedOn = obj.CreatedOn;
Entities.ProImage_Shoping.Add(obj);
Entities.SaveChanges();

}
else
{

}


}
else
{

}
}
Posted
Comments
JMK-NI 21-Aug-14 2:55am
   
You haven't declared obj
awaisshabir 21-Aug-14 4:47am
   
Thanks sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900