⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getimage.ashx

📁 做Web开发大多都要用的GridView,这个讲座可以让你随心所欲的使用GridView
💻 ASHX
字号:
<%@ WebHandler Language="C#" Class="GetImage" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data.Sql;

public class GetImage : IHttpHandler {
	 public void ProcessRequest (HttpContext context) {


         using (SqlConnection sc = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
         {
             sc.Open();
             String txtsql = "select photo from employees where employeeid=" + context.Request.QueryString["eid"];
             SqlCommand scd = new SqlCommand(txtsql, sc);

             context.Response.Clear();
             context.Response.ContentType = "image/bmp";

             byte[] bitmapBytes = (byte[])scd.ExecuteScalar();
             int length = bitmapBytes.Length;

             context.Response.OutputStream.Write(bitmapBytes, 78, bitmapBytes.Length - 78);
             context.Response.Cache.SetCacheability(HttpCacheability.Public);
         }

         context.Response.End();
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -