Example #1
0
        public ActionResult SaveBanner(string Action)
        {
            string BannerCatId = Request.Form["BannerCatId"];
            //string Bannername = Request.Form["Bannername"];
            string BannerId = Request.Form["BannerId"];

            string fname  = "";
            string myfile = "";
            string save   = "";

            if (Request.Files.Count > 0)
            {
                HttpFileCollectionBase files = Request.Files;

                //var path = System.Web.HttpContext.Current.Server.MapPath("~/Uploads");

                DataTable dt = objBannerManager.SaveBanner(Action, BannerCatId);

                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFileBase file = files[i];
                    if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
                    {
                        string[] testfiles = file.FileName.Split(new char[] { '\\' });
                        fname = testfiles[testfiles.Length - 1];
                    }
                    else
                    {
                        myfile = Guid.NewGuid() + "-" + Path.GetFileName(file.FileName);
                        //filename = file.FileName;
                    }
                    var path = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    fname = Path.Combine(path + myfile);
                    //fname = Path.Combine(Server.MapPath("~/Uploads/") + filename);
                    file.SaveAs(fname);
                    save = objBannerManager.SaveBannerDetail(Action, dt.Rows[0]["BannerId"].ToString(), myfile);
                }
            }

            return(Json(new { save }));
        }