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
Guest User
Tech Writer
611
127.1k
Upload different different image.
Mar 3 2020 12:06 AM
How too upload image different different in mvc single click.
if
(ModelState.IsValid)
{
if
(Request.Files.Count > 0)
{
HttpPostedFileBase file = Request.Files[0];
if
(file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var supportedTypes =
new
[] {
"jpg"
,
"jpeg"
,
"gif"
,
"x-png"
,
"png"
};
var fileExt = System.IO.Path.GetExtension(fileName).Substring(1);
if
(supportedTypes.Contains(fileExt))
{
obj_tblNews.NewsImage = Path.Combine(
Server.MapPath(
"~/Content/Upload"
), fileName);
file.SaveAs(obj_tblNews.NewsImage);
obj_tblNews.NewsImage = file.FileName;
_db.tblNews.Add(obj_tblNews);
_db.SaveChanges();
ModelState.Clear();
}
//if(supportedTypes1.Contains(fileExt1))
//{
// obj_tblNews.BannerImage = Path.Combine(
// Server.MapPath("~/Content/Upload"), fileName1);
// file.SaveAs(obj_tblNews.BannerImage);
// obj_tblNews.BannerImage = file.FileName;
// _db.tblNews.Add(obj_tblNews);
// _db.SaveChanges();
// ModelState.Clear();
//}
}
}
}
}
it's me code . comment code second image for . This code run successfull but store same image path in database.
Reply
Answers (
1
)
search array n give index
How to zip multiple folder at a time.