PDA

View Full Version : فراخوانی عکس از بانک اطلاعاتی



General-Xenon
پنج شنبه 20 اسفند 1388, 04:08 صبح
سلام.........................!




<%@WebHandlerLanguage="C#‎‎"Class="DB_IMG" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;
using System.Collections;
public classDB_IMG : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
SqlConnection CN336546546 = newSqlConnection(Connection String);

context.Response.ContentType = "image/jpeg";
context.Response.Cache.SetCacheability(HttpCacheab ility.NoCache);
context.Response.BufferOutput = false;
string enc1 = "";
string enc2 = "";
if (context.Request.QueryString["cid"] != null && context.Request.QueryString["cid"] != "")
enc1 = context.Request.QueryString["cid"].ToString();
System.IO.MemoryStream strm = new System.IO.MemoryStream();
try
{
CN336546546.Open();
SqlCommand cmd = newSqlCommand("SELECT [PIMAGE] FROM [TBPROJECT] WHERE [ID]='" + enc1 + "'", CN336546546);
byte[] img = (byte[])cmd.ExecuteScalar();
strm.Write(img, 0, img.Length);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(strm);
bmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
finally
{
CN336546546.Close();
strm.Close();
}
}
public bool IsReusable {
get {
return true;
}
}
}