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.9k
upload multiple images in .net core
Aug 5 2020 11:58 PM
Upload Multiple Images And Store each image path in different column in c#.
1 Throwing NULL NULL NULL throwing_white.png throwing_black.png for e.g i have first select throwing_white and second select throwing_black.png . How to store different column a image path
2 Catching NULL NULL NULL catching_white.png catching_black.png
3 Running NULL NULL NULL running_white.png running_black.png
4 Hitting NULL NULL NULL hitting_white.png hitting_black.png
5 Fielding NULL NULL NULL fielding_white.png fielding_black.png
6 Soft Tissue Mobility 2020-07-20 17:30:44.220 1 NULL soft_tissue_white.png soft_tissue_black.png
it's me upload and add code
public
async Task<IActionResult> AddCategories(CategoriesViewModel obj_Parameter, List<IFormFile> CategoriesImages)
{
CategoryMaster obj_category =
new
CategoryMaster();
try
{
string
filePath =
""
;
if
(CategoriesImages !=
null
&& CategoriesImages.Count > 0)
{
return
Content(
"File(s) not selected"
);
}
else
{
foreach
(IFormFile image
in
CategoriesImages)
{
var wwwrootPath = webHost.ContentRootPath +
"\\wwwroot\\CategoryImage\\"
;
string
thisFileName = Path.Combine(image.FileName);
if
(image?.Length > 0)
{
filePath = Path.Combine(wwwrootPath, image.FileName);
using
FileStream fileStream =
new
FileStream(filePath, FileMode.Create);
await image.CopyToAsync(fileStream);
}
obj_category.CategoryWhiteImage = thisFileName;
obj_category.CategoryBlackImage =
""
;
obj_category.IsActive =
true
;
obj_category.CategoryName = obj_Parameter.CategoryName;
obj_category.UpdatedDate = DateTime.UtcNow;
}
await _context.CategoryMaster.AddAsync(obj_category);
await _context.SaveChangesAsync();
}
}
catch
(Exception ex)
{
it's me view code.
@using (Html.BeginForm(
"AddCategories"
,
"CategoriesManagement"
, FormMethod.Post,
new
{ enctype =
"multipart/form-data"
}))
{
<div
class
=
"modal-content"
>
<div
class
=
"modal-header"
>
<h5
class
=
"modal-title has-icon ms-icon-round "
>Add New Category</h5>
<button type=
"button"
class
=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span aria-hidden=
"true"
>×</span></button>
</div>
<div
class
=
"modal-body"
>
<form action=
"/action_page.php"
>
<div
class
=
"ms-form-group"
>
<label
for
=
"img"
>Select image:</label>
<input type=
"file"
id=
"CategoriesImage"
name=
"CategoriesImages"
accept=
"image/*"
multiple=
"multiple"
/>
</div>
<div
class
=
"ms-form-group has-icon"
>
<label
for
=
"choosecategory"
>Enter Category</label>
@Html.TextBoxFor(x => x.CategoryName,
new
{ @type =
"text"
, @id =
"ImageName"
, @
class
=
"form-control"
, @placeholder =
"Enter Name"
})
@*<input type=
"text"
class
=
"form-control"
placeholder=
"Enter your Category"
>*@
</div>
</form>
</div>
<div
class
=
"modal-footer"
>
<button type=
"button"
class
=
"btn btn-light"
data-dismiss=
"modal"
>Cancel</button>
<button type=
"submit"
class
=
"btn btn-info shadow-none"
id=
"SubmitCategories"
>Submit</button>
</div>
</div>
}
Reply
Answers (
1
)
Looping in SQL with Where condition
Authentication in asp.net