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
taha suliman
1.4k
368
6.5k
Can not Upload All files using Dropzone Multifiles upload ,MVC C#,
Jun 29 2020 9:39 AM
I added a drop-down library to my project when I picked a bunch of files.
And press the file upload button. The code only uploads one file and ignores the rest of the files.
It does not save the name and extension of files in the database. I don’t know where the error is ??
Note: All files are successfully uploaded if the save code is cleared
public
ActionResult Upload()
{
FILES_TABLE ft =
new
FILES_TABLE();
bool
isSavedSuccessfully =
true
;
string
fName =
""
;
try
{
foreach
(
string
fileName
in
Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
fName = file.FileName;
if
(file !=
null
&& file.ContentLength > 0)
{
var path = Path.Combine(Server.MapPath(
"~/MyImages"
));
string
pathString = System.IO.Path.Combine(path.ToString());
string
fileName1 = Path.GetFileName(file.FileName);
string
ext1 = System.IO.Path.GetExtension(file.FileName);
bool
isExists = System.IO.Directory.Exists(pathString);
if
(!isExists) System.IO.Directory.CreateDirectory(pathString);
var uploadpath =
string
.Format(
"{0}\\{1}"
, pathString, file.FileName);
file.SaveAs(uploadpath);
ft.FileName = fileName1;
ft.FileExt = ext1;
_DB.FILES_TABLE.Add(ft);
_DB.SaveChanges();
}
}
}
catch
(Exception ex)
{
isSavedSuccessfully =
false
;
ViewBag.Err =
"{0} Exception caught."
+ ex;
}
if
(isSavedSuccessfully)
{
return
RedirectToAction(
"Index"
);
}
else
{
return
Json(
new
{
Message =
"Error in saving file"
});
}
}
Reply
Answers (
1
)
How to display text box value
Windows application