how to display image preview before upload to server

Posted by reddysankark-13471 under ASP.NET on 10/19/2012 | Points: 10 | Views : 3230 | Status : [Member] | Replies : 2
hi ,
i need coding for how to display preview image before upload to server asynchronously with out using preview button.

sankarreddy


Responses

Posted by: Rickeybglr on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
try to set path of image to image control before uploading it on preview button click event.
wht i did is tht i uploaded the pic and store into asp folder and display pic frm ther
objcUserInfo.ImageName = FUImage.FileName; //upload control id
string folderName = objcUserInfo.Username;
if (Directory.Exists(Server.MapPath("images\\UserProfileDP\\" + folderName)))
{
// return null;
}
else
{
Directory.CreateDirectory(Server.MapPath("images\\UserProfileDP\\" + folderName));
string imzName = Path.GetFileName(FUImage.FileName);
string path = Server.MapPath("images\\UserProfileDP\\" + folderName + "/" + imzName);
FUImage.SaveAs(path);
}
objcUserInfo.ImageURL = ("~/images/UserProfileDP/" + folderName + "/" + objcUserInfo.ImageName).ToString
();
diplypreview.imageurl= objcUserInfo.ImageURL;

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Seng2hs on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
<table>
<tr>
<td class="style3">
<asp:Label ID="Label1" runat="server" Text="Photo upload" />
</td>
<td class="style4">
<asp:FileUpload runat="server" ID="PhotoUpload" />
</td>
<td class="style4">
<asp:Button runat="server" OnClick="btnPreview_Click" ID="btnPhotoPreview" Text="Preview" />
</td>
<td class="style1">
<asp:Image runat="server" ID="ImagePreview" Height="164px" Width="125px" />
</td>
</tr>
</table>

****************************************************************************************************************************

using System;
using System.Web;

public class ImageHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

public void ProcessRequest (HttpContext context) {
//Checking whether the imagebytes session variable have anything else not doing anything

if ((context.Session["ImageBytes"]) != null)
{
byte[] image = (byte[])(context.Session["ImageBytes"]);
context.Response.ContentType = "image/JPEG";
context.Response.BinaryWrite(image);
}
}

public bool IsReusable {
get {
return false;
}
}
}

****************************************************************************************************************************

protected void btnPreview_Click(object sender, EventArgs e)
{
Session["ImageBytes"] = PhotoUpload.FileBytes;
ImagePreview.ImageUrl = "~/ImageHandler.ashx";
}
Just rewrite the code inside processrequest to get the session variable and generate the image

reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response