6 Months Free & No Setup Fees ASP.NET Hosting!
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » ASP.NET & Web Development » how to show uploaded image in web form
       
Author Reply
rajath r
posted 26 posts
since Jul 30, 2010 
from

how to show uploaded image in web form

  Posted on: 27 Aug 2010       
Hi friends.

I am developing an web application. here i am using file uploader  and i am uploading images.

Problem here is, i need to provide preview of uploaded image as soon as file is uploaded.

How can i do this.

Regards

Rajath
Manikavelu Velayutham
posted  689 posts
since  Jun 25, 2010 
from 

 Re: how to show uploaded image in web form
  Posted on: 27 Aug 2010        0  

you can put the html image tag, and pass the url of that image in that.
<img....../>
just put a preview button over there, through that just hide and show the image. you should dynamically change the image url, so that the uploaded image will be get previewed.
Mark this post as answered, if this really helps you.
If you find my post helpful, Mark it as Answered or Rate the post.
Shankey
posted  178 posts
since  Aug 05, 2010 
from 

 Re: how to show uploaded image in web form
  Posted on: 27 Aug 2010   Accepted Answer     1  

Hi rajath r,

Following is your solution ,

But don't forget to mark my answer as accepted if it helped you :)

And if you want to upload .gif file then change folllowing condition

  if (Extension == "jpg" || Extension == "JPG" ||  Extension == "JPEG"  || Extension == "jpeg")

Aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

    <script language="javascript" type="text/javascript">
    function ValidateFileUpload(Source, args)
                {
                  var fuData = document.getElementById('<%= fileUploadImage.ClientID %>');
                  var FileUploadPath = fuData.value;
                
                  if(FileUploadPath =='')
                  {
                    // There is no file selected
                    args.IsValid = true;
                  }
                  else
                  {
                    var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();
                
                    if (Extension == "jpg" || Extension == "JPG" ||  Extension == "JPEG"  || Extension == "jpeg")
                    {
                    
                      args.IsValid = true; // Valid file type
                    }
                    else
                    {
                      args.IsValid = false; // Not valid file type
                    }
                   }
                }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Image ID="imgShow" runat="server" />
        <asp:FileUpload ID="fileUploadImage" runat="server" size="10" />
        <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click" Text="Upload" />
       <asp:CustomValidator runat="server" ID="cv" ClientValidationFunction='ValidateFileUpload' ControlToValidate='fileUploadImage' ErrorMessage='You can upload only jpg/jpeg file' ></asp:CustomValidator>
    </div>
    </form>
</body>
</html>


C# code

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fileUploadImage.FileName != "")
        {
            String fullpath = Server.MapPath(fileUploadImage.FileName);
            fileUploadImage.SaveAs(fullpath);
            imgShow.ImageUrl = fileUploadImage.FileName;
        }
    }
}

If this post helped you, then tick the checkbox above "Do you like this Answer"
Shakey Shankey
       
6 Months Free & No Setup Fees ASP.NET Hosting!
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved