0

I want to save PDF file that generated in the path that user want for example Desktop or whatever , i have 2 button in the same page, the first is to generate report and the second to save the report as pdf , could any one help me how to do that like this box

 PdfPTable tablee = new PdfPTable(3);
            tablee.AddCell("ID");
            tablee.AddCell("AGE");
            tablee.AddCell("NAME");
            lenthee = db.persions.ToArray().Length;
            persion[] array = new persion[lenthee];
            array = db.persions.ToArray();
            for (int i = 0; i < lenthee; i++)
            {
                tablee.AddCell(array[i].ID.ToString());
                tablee.AddCell(array[i].age.ToString());
                tablee.AddCell(array[i].name.ToString());
            }

            Document doc = new Document(PageSize.A4, 1, 1, 1, 1);

            // here i want to ask the user where to he want to save the file (dialog box)then put the path in (path String attribute)
             String path = "C:\\Users\\se\\Desktop\\test.pdf";
            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create));
            doc.Open();
            Paragraph s = new Paragraph("report");
            doc.Add(s);
            doc.Add(tablee);
            doc.Close();
SLEO
  • 73
  • 1
  • 2
  • 6
  • You can't save it to user's machine. You just write the document out and let the user choose where to save it – Sami Kuhmonen Feb 06 '16 at 17:06
  • From server code, you cannot save some file to users machine. What you can do is , return a file /file stream back to the browser and based on the browser setting, It will ask the user to download the file / open it. Take a look at [this](http://stackoverflow.com/questions/13219704/mvc3-pdf-viewer/13219775#13219775) post or [this](http://stackoverflow.com/questions/11004470/need-help-adding-download-feature-to-mvc-application/11004548#11004548) – Shyju Feb 06 '16 at 17:10
  • so you mean Sami Kuhmonen that i have to open the PDF file in the browser then the user will save it ? – SLEO Feb 06 '16 at 17:20
  • You stream it to the browser through something like Response.TransmitFIle(). You can set the mime content type though to one recognized as a pdf, or to something else such as an octet-stream, and since the browser doesn't know what to do with the MIME type it asks tov view or save. A simple example is at: http://www.c-sharpcorner.com/uploadfile/afenster/how-to-download-a-file-in-Asp-Net/ – Mark Fitzpatrick Feb 07 '16 at 02:36

0 Answers0