Thursday, July 10, 2025

How to download pdf file from server not on database only on server - Simplest way

//only two lines code is required that is uncommented

//Response.Clear(); // This is i am not using because response.clear is used for clearing http response (like text) but this is a file that is presently on server. Also when we create pdf of text file than we use clear function and we are getting pdf file from database (binary fromat) Response.buffer is default true so we don't need.

 Response.AddHeader("content-disposition", "attachment; filename=t.pdf"); 

 //Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf; 

        //"application/octet-stream"; 

        Response.WriteFile(Server.MapPath("~/App_Data/Annexure.pdf")); // File must be there on server otherwise it will give error


//Response.end is also we are not using because we are not creating pdf file , if we create pdf file or we are getting from database than we use Response.End and Response.Clear() functions.

No comments:

Post a Comment