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

No comments:

Post a Comment