locked
Image handler not reloading my image! Or my defualt image . RRS feed

  • Question

  • hello 
    im using handlers to do upload edit delete images its work just fine ! but when i delete and set a defualt image dosnot show up until i refresh the page !

    What I have tried:

    public class Handler1 : IHttpHandler, IRequiresSessionState
    {
    public static string strCon = System.Configuration.ConfigurationManager.AppSettings["connectionstring"];
    public void ProcessRequest(HttpContext context)
    {
    SqlConnection _con = new SqlConnection(strCon);
    var id = context.Request.Params.GetValues("id");
    int ImgNumber = Convert.ToInt32(id[0].ToString());
    int wasteCheckID = Convert.ToInt32(context.Session["WasteCheckID"]);
    string stDelete = "DELETE FROM tbl_LogisticsWasteCheckImg WHERE WasteCheckID=" + wasteCheckID + " AND ImgNumber=" + ImgNumber;
    SqlCommand cmdDelete = new SqlCommand(stDelete, _con);
    _con.Open();
    cmdDelete.ExecuteNonQuery();
    _con.Close();
    string strget = "select img from tbl_logisticswastecheckimg where wastecheckid=114 and imgnumber=1";
    _con.Open();
    using (SqlDataAdapter sda = new SqlDataAdapter(strget, _con))
    {
    DataTable dt = new DataTable();
    sda.Fill(dt);
    if (dt.Rows.Count > 0)
    {
    byte[] bytes = (byte[])dt.Rows[0]["img"];
    context.Response.BinaryWrite(bytes);
    
    context.Response.End();
    }
    else
    {
    context.Response.WriteFile("~/images/a.png");
    //read image file into image object.
    Image img = Image.FromFile(context.Server.MapPath("~/images/a.png"));
    
    //imageconverter class convert image object to byte array.
    byte[] bytes = (byte[])(new ImageConverter()).ConvertTo(img, typeof(byte[]));
    context.Response.BinaryWrite(bytes);
    context.Response.End();
    }
    }
    }
    public bool IsReusable
    {
    get
    {
    return false;
    }
    }
    }
    }


    • Moved by CoolDadTx Thursday, October 11, 2018 2:46 PM ASP.NET related
    Thursday, October 11, 2018 11:44 AM

All replies

  • Please post questions related to web development in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, October 11, 2018 2:46 PM