How to show image in imagebox as soon as fileuploader control selects image file

Posted by Shwetabansal888 under Regular Expressions on 6/28/2010 | Views : 3107 | Status : [Member] | Replies : 3
All Dear,
Can anyone help me out about How to show image in imagebox /picturebox control as soon as fileuploader control selects image file in asp.net 3.5,C# web application.
Regards,
Shweta




Responses

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Shweta

try this Code

Session["Fname"] = fup1.FileName;
fup1.SaveAs(Server.MapPath(".") + fup1.FileName);
im1.ImageUrl =Server.MapPath(".")+"/"+ Session["Fname"].ToString();



Mark as Answer if its helpful to you

Shwetabansal888, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/29/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Shwetabansal888, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Solijoseph on: 9/29/2012 [Member] Starter | Points: 25

Up
0
Down
<input type="file" id="hmFile" runat="server" />

$("#<%=hmFile.ClientID%>").live("change", function (e) {

var filename = document.getElementById("<%=hmFile.ClientID%>").value;
var exn = "";
var i = filename.lastIndexOf('.');

if (i !== -1) {
exn = filename.slice(i + 1);
}
if (exn !== "") {
if (CheckValidFile(exn)) { //CheckValidFile() function check whether the selected file is valid
//Bind selected image with control from server side
// __doPostBack("", document.getElementById("<%=hidImageID.ClientID%>").value);
// Or use ajax
}
else {
alert("Unable to process this photo. Please check your photo's format and try again.\n We support these photo formats: JPG, JPEG, GIF, PNG, and BMP");

}
}
});

..........................................................

function CheckValidFile(exn) {
var newext = exn.toLowerCase();
if (newext == "jpg" || newext == "bmp" || newext == "jpeg" || newext == "png" || newext == "gif") {

return true;
}
else {

return false;
}
}

..............................................

Use
__doPostBack("IMAGE",exn ); // A postback occurs when execute this line

In the Server side

if (IsPostBack)
{
string parameter = Request.Form["__EVENTTARGET"];
string argument = Request.Form["__EVENTARGUMENT"];
if (parameter == "IMAGE")
{
hmFile.PostedFile.SaveAs("../Image/Test."+argument ); //argument contain image extension
imgCtrl1.ImageUrl="../Image/Test."+argument ;
// Alternate Method, Use httphandler and bind ImageStream with image Controller

}

Thanks & Regards
Solimon Joseph

Shwetabansal888, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response