Multiple file upload store the file path in sql with ASP.NET WebApi.I can store multiple image on folder. But image path store only once.I want to store image path also multiple time
- public string UploadFiles()
- {
- int iUploadedCnt = 0;
-
-
- string sPath = "";
- sPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/");
-
- System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
-
-
- for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
- {
- System.Web.HttpPostedFile hpf = hfc[iCnt];
-
- if (hpf.ContentLength > 0)
- {
-
- if (!File.Exists(sPath + Path.GetFileName(hpf.FileName)))
- {
-
- hpf.SaveAs(sPath + Path.GetFileName(hpf.FileName));
- iUploadedCnt = iUploadedCnt + 1;
-
- HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];
-
-
- WebApiDatabaseEntities entities = new WebApiDatabaseEntities();
- ImageUpload file = new ImageUpload();
-
- file.ImagePath = Path.GetFileName(postedFile.FileName);
- file.Title = postedFile.ContentType;
- file.CreatedDate = DateTime.Now;
-
- entities.ImageUploads.Add(file);
- entities.SaveChanges();
- }
- }
- }
- }