Asp.Net Save File on client machine

Recently I had a task to save file on client machine. We usually save file on server and in ASP.NET the more familiar task to save on client side was to export gridview results to excel file. This time the task was to save an image on client machine. Following is the code that I followed.

 

<pre name="code" class="html">

byte[] fileBytes = File.ReadAllBytes("D:\\Projects\\TestClientDownload\\images\\banner_ad_1.jpg");

       Response.ClearContent();
       Response.ClearHeaders();
       Response.ContentType = "text/plain";
       Response.AppendHeader("content-disposition", "attachment; filename=" + "banner_ad_1.jpg");
       Response.AppendHeader("content-length", fileBytes.Length.ToString());
       Response.BinaryWrite(fileBytes);
       Response.Flush();
       Response.End();

</pre>

Comments

Popular posts from this blog

Weekend Gateway Trip - Shrivardhan

Cross Apply Incorrect syntax near '.'

Apply CSS Class based on Browser