Click here to Skip to main content
16,021,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,
i am using in my project using images ,videos i want to retrive those how can i implment can i write separate or single handler for all processes guide me
or send any snippets
Posted

Hi,
This sample code for retrieve images from database and display on web page. And videos or images everything need to convert to byte array forma after that we can store or retrieve.

Use this sample,

public class Retrieve : IHttpHandler 
{
    
    public void ProcessRequest (HttpContext context) 
    {
        if (context.Request.QueryString != null)
        {
            string connectionString = ConfigurationManager.AppSettings["ConnectionString"].ToString();
            SqlConnection dbConnection = new SqlConnection(connectionString);
            string personid = context.Request.QueryString["PID"];          
            dbConnection.Open();
            SqlCommand command = new SqlCommand("SELECT Photo FROM [ProspectDetail] WHERE PersonID = " + personid, dbConnection);          

            SqlDataReader dr;
            if (personid != null)
            {
                dr = command.ExecuteReader();

                while (dr.Read())
                {
                    try
                    {
                        byte[] bt = (byte[])dr["Photo"];
                        if (bt.GetLength(0) != 0)
                        {
                            context.Response.BinaryWrite((byte[])dr["Photo"]);
                        }
                    }
                    catch (SqlException exe)
                    {
                        ErrorLog err = new ErrorLog();
                        err.GetErrorLog(exe.Message);
                    }
                    finally
                    {
                        dbConnection.Close();
                        context.Response.End();
                    }
                }        

                
            }                       
            
        }
        //context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
    }
 
    public bool IsReusable 
    {
        get 
        {
            return false;
        }
    }
}
 
Share this answer
 
Refer These Links

1. http://www.worldofasp.net/tut/images/Displaying_images_in_ASPNET_using_HttpHandlers_92.aspx[^]

2.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=129[^]

Accept The Answer If It Has Helped You. This Will Boost The Confidence Of The Users Who Are Helping The Needful
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900