Thursday, August 14, 2025

How to display binary images from database - How to view images from database - view binary images - asp.net c# - How to download file from database

protected void FetchImage(object sender, EventArgs e)

{

    string id = ddlImages.SelectedItem.Value;

    Image1.Visible = id != "0";

    if (id != "0")

    {

        byte[] bytes = (byte[])GetData("SELECT Data FROM tblFiles WHERE Id =" + id).Rows[0]["Data"];

        string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);

        Image1.ImageUrl = "data:image/png;base64," + base64String;

    }

}


ref:- https://www.aspsnippets.com/Articles/660/Display-image-from-database-in-Image-control-without-using-Generic-Handler-in-ASPNet/ 

How to run background music in website - HTML

 https://www.tutorialspoint.com/how-to-add-background-music-to-your-web-page

Tuesday, August 12, 2025

How to download file using binarywrite function and download file from url link - using webclient function

  protected void btnClickMe_Click(object sender, EventArgs e)

    {

                WebClient client = new WebClient();

        byte[] bytes = client.DownloadData("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgahqj6mU5OTtB-PLGl36tvYYv02OuXuR__pTakG-Y8dBc36TZaSboLga6RwM8DJUQKAwJ_sSjkp-4nhW1udweEejazbrZ50z2cb1ynJgIaZNBlrSIy827bc_5iY6UesB4/s220/WIN_20220808_12_53_18_Pro.jpg");

        Response.Clear(); //This must be add ,without this the file that you save will not be open

        Response.AddHeader("content-disposition", "attachment; filename=1.jpg"); 

         


 //Response.ContentType = System.Net.Mime.MediaTypeNames.Image.Jpeg; 


        //"application/octet-stream"; 


        Response.BinaryWrite(bytes);

        Response.Flush();

        Response.End();

    }


Note:-         Response.Clear(); //This must be add ,without this the file that you save will not be open