TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
selvi jp
NA
323
78k
Multiple file upload with ASP.NET WebApi
May 8 2021 2:51 AM
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;
// DEFINE THE PATH WHERE WE WANT TO SAVE THE FILES.
string
sPath =
""
;
sPath = System.Web.Hosting.HostingEnvironment.MapPath(
"~/Images/"
);
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)
{
// CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. (AVOID DUPLICATE)
if
(!File.Exists(sPath + Path.GetFileName(hpf.FileName)))
{
// SAVE THE FILES IN THE FOLDER.
hpf.SaveAs(sPath + Path.GetFileName(hpf.FileName));
iUploadedCnt = iUploadedCnt + 1;
//Read the File data from Request.Form collection.
HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];
//Insert the File to Database Table.
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();
}
}
}
}
Reply
Answers (
1
)
asp.net core build a matrix 5x5 and apply style
Label1 doesn't exist in current context