What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 20497 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET > how to display image preview before upload to server ...
Reddysankark@Yahoo.Com

how to display image preview before upload to server

Replies: 2 | Posted by: Reddysankark@Yahoo.Com on 10/19/2012 | Category: ASP.NET Forums | Views: 939 | Status: [Member] | Points: 10  


hi ,
i need coding for how to display preview image before upload to server asynchronously with out using preview button.

sankarreddy


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Rickeybglr
Rickeybglr  
Posted on: 10/23/2012 5:55:16 AM
Level: Starter | Status: [Member] | Points: 25

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@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Seng2hs
Seng2hs  
Posted on: 10/23/2012 7:11:57 AM
Level: Starter | Status: [Member] | Points: 25

<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@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 1:14:16 AM