Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 21, 2012 02:48 AM by santa_1975
Participant
896 Points
238 Posts
Jun 20, 2012 11:21 AM|LINK
file upload control with image control ...
when fileupload browse button click, i want to browse only images and the selected image display on the image control..
how can i do it ???
plz help with the code...
Member
64 Points
31 Posts
Jun 21, 2012 02:37 AM|LINK
hi,
try this code to upload only image.
protected void btnInsert_Click(object sender, EventArgs e) { string Filename = ""; if (FileUpload.HasFile) { HttpPostedFile postedfile = FileUpload.PostedFile; FileInfo info = new FileInfo(FileUpload.FileName); String fileextention = info.Extension.ToLower(); if (fileextention != ".jpg" && fileextention != ".jpeg" && fileextention != ".png" && fileextention != ".gif") { LblMsg.Visible = true; LblMsg.Text = "Please Upload .jpg/.jpeg/.png/.gif"; return; } else { LblMsg.Visible = false; Filename = "MyImage/" + FileUpload.FileName; //i send this file name to my database objClass.Image = Filename; objClass.Name = txtName.Text.Trim(); } } objClass.UserId = Convert.ToString(Session["username"]); bool Status = objController.InsertName(objClass, null); if (Status) { if (FileUpload.HasFile) FileUpload.SaveAs(Server.MapPath("~/" + Filename)); //hear i save the image to image folder LblMsg.Visible = true; LblMsg.Text = "Inserted Successfully; FillImageControl(); } else { LblMsg.Visible = true; LblMsg.Text = "Name Already Exists"; txtName.Text = ""; } }
Star
8574 Points
1499 Posts
Jun 21, 2012 02:48 AM|LINK
This jQuery demo looks great!
http://blueimp.github.com/jQuery-File-Upload/
Hope this helps.
Mahesh Darku...
Participant
896 Points
238 Posts
Asp .net fileupload control
Jun 20, 2012 11:21 AM|LINK
file upload control with image control ...
when fileupload browse button click, i want to browse only images and the selected image display on the image control..
how can i do it ???
plz help with the code...
Alok Rawat
Member
64 Points
31 Posts
Re: Asp .net fileupload control
Jun 21, 2012 02:37 AM|LINK
hi,
try this code to upload only image.
protected void btnInsert_Click(object sender, EventArgs e)
{
string Filename = "";
if (FileUpload.HasFile)
{
HttpPostedFile postedfile = FileUpload.PostedFile;
FileInfo info = new FileInfo(FileUpload.FileName);
String fileextention = info.Extension.ToLower();
if (fileextention != ".jpg" && fileextention != ".jpeg" && fileextention != ".png" && fileextention != ".gif")
{
LblMsg.Visible = true;
LblMsg.Text = "Please Upload .jpg/.jpeg/.png/.gif";
return;
}
else
{
LblMsg.Visible = false;
Filename = "MyImage/" + FileUpload.FileName; //i send this file name to my database
objClass.Image = Filename;
objClass.Name = txtName.Text.Trim();
}
}
objClass.UserId = Convert.ToString(Session["username"]);
bool Status = objController.InsertName(objClass, null);
if (Status)
{
if (FileUpload.HasFile)
FileUpload.SaveAs(Server.MapPath("~/" + Filename)); //hear i save the image to image folder
LblMsg.Visible = true;
LblMsg.Text = "Inserted Successfully;
FillImageControl();
}
else
{
LblMsg.Visible = true;
LblMsg.Text = "Name Already Exists";
txtName.Text = "";
}
}
santa_1975
Star
8574 Points
1499 Posts
Re: Asp .net fileupload control
Jun 21, 2012 02:48 AM|LINK
This jQuery demo looks great!
http://blueimp.github.com/jQuery-File-Upload/
Hope this helps.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"