selvi jp

selvi jp

  • NA
  • 323
  • 69.5k

upload image on folder with compressed size web api

May 12 2021 11:41 AM
upload image on folder with compressed size web api.
 
 string sPath = "";
            sPath = HostingEnvironment.MapPath("~/Images/");
            WebApiDatabaseEntities entities = new WebApiDatabaseEntities();
            System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
         
            // CHECK THE FILE COUNT.
            for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
            {
                System.Web.HttpPostedFile hpf = hfc[iCnt];
               
                    if (hpf.ContentLength > 0)
                {
                  

                    // SAVE THE FILES IN THE FOLDER.   
                    var fileName = Path.GetFileName(hpf.FileName);
                    var random = Guid.NewGuid() + fileName;
                    hpf.SaveAs(sPath + Path.GetFileName(random));
                        iUploadedCnt = iUploadedCnt + 1; here i am storing image in folder

Answers (3)