jeudi 16 juin 2016

when i call Image its showing binary code

I'm using Generic Handler in to display image its working great but when i open image in new tab i.e


In new Tab its showing binary code but i want to display Image how to achieve this below is my code i'm using in my Generic Hander (ImageHandler.ashx.cs)

public void ProcessRequest(HttpContext context)
  string ID = context.Request.QueryString["ImageID"];
  if (ID!= "")
   SqlConnection connection = new SqlConnection("Server=.; Database=master; User Id=sa; Password=tiger;");
   SqlCommand cmd = new SqlCommand("[spGetImage]", connection);
   cmd.CommandType = CommandType.StoredProcedure;
   cmd.Parameters.AddWithValue("@imgID", ID);
   SqlDataAdapter da = new SqlDataAdapter(cmd);
   DataSet ds = new DataSet();
   //Get Image Data
   byte[] file = null;
   if (ds.Tables[0].Rows.Count > 0)
     file = (byte[])ds.Tables[0].Rows[0]["img"];

    MemoryStream memoryStream = new MemoryStream();
    memoryStream.Write(file, 0, file.Length);
    System.Drawing.Bitmap _bitMap = new System.Drawing.Bitmap(memoryStream);
    context.Response.Buffer = true;

Aucun commentaire:

Enregistrer un commentaire