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
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Uploading Multiple image through file upload and saving to database ASP.NET
Pintoo Yadav
Mar 28
2015
Code
25.4
k
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
< asp: FileUpload AllowMultiple =
"true"
ID =
"fileuploadimages"
runat =
"server"
/ > < asp: Button runat =
"server"
ID =
"btnUpload"
CssClass =
"btnStyle"
Text =
"Upload Image"
OnClick =
"btnUpload_Click"
/ >
protected
void
btnUpload_Click(
object
sender, EventArgs e)
{
if
(fileuploadimages.HasFile ==
false
)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(),
"key"
, "
<script>alert(
'No File Uploaded.'
)</script>",
false
);
}
else
{
foreach
(var file
in
fileuploadimages.PostedFiles)
{
string
filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
fileuploadimages.SaveAs(Server.MapPath(
"../Pictures/"
+ filename));
SqlCommand cmd =
new
SqlCommand("Insert into
EventPageView(Event_name,Event_Text,Image_Path)
values(@EventName,@EventText,@ImagePath)", conn);
cmd.Parameters.AddWithValue(
"@ImagePath"
, filename);
cmd.Parameters.AddWithValue(
"@EventName"
, txtEventName.Text);
cmd.Parameters.AddWithValue(
"@EventText"
, txtEnterDesc.Text);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
BindDataList();
}
}
}
ASP.NET file upload
ASP.NET
C#
SQL Server database