Popular Posts
android.intent.action.SCREEN_ON & android.intent.action.SCREEN_OFF First, I've tried create a receiver to receive screen on/off and register receiver on AndroidManifest.xml like below, but unfortunately ... Memo: Debounce Task To prevent multi-execution from caller in short time, use debounce for single execution. var debounce = function (func, threshold, execAsap... Multiple line of text limit With Sharepoint Designer, edit the page of list view. Add xsl template as below to override original template. Source template could be foun...
Blog Archive
Stats
Read image from database and write into response
<%@ WebHandler Language="C#" Class="Image" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
public class Image : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        if (string.IsNullOrEmpty(context.Request.QueryString["id"]))
        {
            context.Response.StatusCode = "404";
            context.Response.End();
        }
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[VarHelper.ConnStrLocal].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("SELECT [MimeType], [Image] FROM [ImageAlbum] WHERE [ImageID] = @ImageID", conn);
            cmd.Parameters.Add("@ImageID", System.Data.SqlDbType.Int).Value = context.Request.QueryString["id"];

            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                byte[] data = null;
                string contentType = string.Empty;
                while (reader.Read())
                {
                    data = (byte[])reader["Image"];
                    contentType = (string)reader["MimeType"];
                }
                context.Response.ContentType = contentType;
                context.Response.BinaryWrite(data);
                context.Response.End();
            }
            else
            {
                context.Response.StatusCode = "404";
                context.Response.End();
            }
            conn.Close();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}