Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi guyss
I am designing UI of Employee master and I want to store image of employee .so user can upload only images like png,jpeg ..etc ..and this image want to display on image control

plese try to help me

Thnxx in advance
Posted
Updated 30-Sep-13 3:10am
v2

Hi,

If you want to place Type checking on your files you can validate only ,.jpg,.jpeg,.png files will be uploaded.

File Upload and Extension Checking

or

File Upload in ASP.NET

Hope this will resolve the issue.


Regards,
Mubin
 
Share this answer
 
Hi,

Try the following one,

1. Create a page called EmployeeImage.aspx

In Page_load, write the following code
C#
MemoryStream msStream = new MemoryStream();

try
{
    if (!(String.IsNullOrEmpty(Request.QueryString["EmployeeId"])))
    {
        gn.cnopen();
        SqlCommand cmdSelect = new SqlCommand("select emp_photo from EMP_PHOTO_DETAILS where emp_id=@ID", gn.cn());
        cmdSelect.Parameters.Add("@ID", SqlDbType.NVarChar, 250);
        cmdSelect.Parameters["@ID"].Value = Request.QueryString["EmployeeId"].ToString();
        byte[] Photo= (byte[])cmdSelect.ExecuteScalar();
            
        msStream.Write(Photo, 0, Photo.Length);
        Bitmap bmpBitmap = new Bitmap(msStream);
        
        Response.ContentType = "image/jpg";
        bmpBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
    }
}
finally
{
    msStream.Close();
}


Your EmployeeImage.aspx will look like below.
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EmployeeImage.aspx.cs" Inherits="EmployeeImage" %>
  
 <!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></title>
 </head>
 <body>
 <form id="form1" runat="server">
 <div>

 </div>
 </form>
 </body>
 </html>
  
 The page you want to display the image, use the following code:
  
 For Image control,
 <asp:Image runat="server" ID="imgEmpPhoto" 
ImageAlign="Top" Width="118" Height="118" />

In code behind to display the image write the following code.
C#
imgDvrPhoto.ImageUrl = String.Format("EmployeeImage.aspx?EmployeeId={0}", txtEmployeeId.Text);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900