在登记表上显示图像 [英] Showing image on registration form

查看:70
本文介绍了在登记表上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好伙伴

我正在设计员工主人的UI,我想存储员工的形象。所以用户只能上传像png,jpeg ..等图片..这个图像想要显示关于图像控制



请尽量帮助我



Thnxx提前

解决方案

您好,



如果您想对文件进行类型检查,您只能验证.jpg,.jpeg。 png文件将被上传。



文件上传和扩展检查







ASP中的文件上传。 NET



希望这可以解决问题。





问候,

Mubin






尝试以下方法,



1.创建一个名为 EmployeeImage.aspx <的页面br $>


Page_load 中,写下以下代码

 MemoryStream msStream =  new  MemoryStream(); 

尝试
{
如果(!( String .IsNullOrEmpty(Request.QueryString [ EmployeeId])))
{
gn.cnopen();
SqlCommand cmdSelect = new SqlCommand( select emp_photo来自EMP_PHOTO_DETAILS,其中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);
位图bmpBitmap = new 位图(msStream);

Response.ContentType = image / jpg;
bmpBitmap.Save(Response.OutputStream,ImageFormat.Jpeg);
}
}
最后
{
msStream.Close();
}





您的 EmployeeImage.aspx 将如下所示。

 <%@     Page    语言  =  C#    AutoEventWireup   =  true   < span class =code-attribute> CodeFile   =  EmployeeImage.aspx.cs   继承  =  EmployeeImage   %>  

< !DOCTYPE < span class =code-attribute> 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 = 服务器 >
< title > < / title >
< ; / head >
< body >
< 表格 id = form1 runat = server >
< div >

< / div >
< /表格 >
< / body >
< / html >

要显示图像的页面,请使用以下代码:

对于图像控制,
< asp:Image runat = server ID = imgEmpPhoto

ImageAlign = Top 宽度 = 118 高度 = 118 / >



在显示图像的代码后面写下面的代码。

 imgDvrPhoto.ImageUrl =  String  .Format(  EmployeeImage.aspx?EmployeeId = {0},txtEmployeeId.Text); 


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

解决方案

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


Hi,

Try the following one,

1. Create a page called EmployeeImage.aspx

In Page_load, write the following code

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.

<%@ 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.

imgDvrPhoto.ImageUrl = String.Format("EmployeeImage.aspx?EmployeeId={0}", txtEmployeeId.Text);


这篇关于在登记表上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆