Click here to Skip to main content
14,924,198 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have one table in sql server now i want to download the table in pdf format and want to be saved in a particular drive with a floder name but one condition download file will not be visible in user just save the file in particular floder

What I have tried:

Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=pratap.pdf");
            //Response.TransmitFile(FilePath);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
            GridView1.AllowPaging = true;
            GridView1.DataBind();
Posted
Updated 20-Mar-18 21:29pm
Comments
Maciej Los 21-Mar-18 3:07am
   
i want to download the table - Can you be more specific?

1 solution

You can't do it.
The problem is the final bit:
Quote:
but one condition download file will not be visible in user just save the file in particular floder
Your server has no control at all over what happens to the file you sent to the user: you have no access to his files, folders, or even to ensure that the file is saved rather than viewed or discarded. All of that is entirely up to the browser (and it's settings) for security reasons - even JavaScript code can't do that!

To generate the file, use something like iTextSharp: c# - How can we export datatable to PDF using iTextSharp? - Stack Overflow[^]
   
Comments
Richard Deeming 21-Mar-18 18:08pm
   
"and it's settings"

Quick - someone call the apostrophe police! :)

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