Click here to Skip to main content
15,938,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

how to get the save dialog box when the pdf is created (using that save dialog box user can mention their save location of generated pdf).
Thankyou.
Posted

Hello, you can try below code:
C#
private void BtnSave_Click(object sender, EventArgs e)
{
    if (this.pdfDocumentViewer1.PageCount > 0)
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "PDF document (*.pdf)|*.pdf";
        DialogResult result = dialog.ShowDialog();
        string fileName = dialog.FileName;
        if (result == DialogResult.OK)
        {
            pdfDocumentViewer1.SaveToFile(fileName);
            MessageBox.Show("You have saved this PdfDocuemnt as:\n" + fileName, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
private void BtnSaveStream_Click(object sender, EventArgs e)
{
    if (this.pdfDocumentViewer1.PageCount > 0)
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "PDF document (*.pdf)|*.pdf";
        DialogResult result = dialog.ShowDialog();
        string fileName = dialog.FileName;
        if (result == DialogResult.OK)
        {
            MemoryStream stream = new MemoryStream();
            pdfDocumentViewer1.SaveToFile(stream);
            byte[] fileBytes = stream.ToArray();
            FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
            fileStream.Write(fileBytes, 0, fileBytes.Length);
            fileStream.Flush();
            fileStream.Close();
            stream.Close();
            MessageBox.Show("You have first saved this PDF docuemnt as memory stream,\nthen write the memory stream in a file :\n" + fileName, "Spire.PdfViewer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
}
 
Share this answer
 
XML
hi friend,
if u take any link button in design page assume it is like "LinkButtonDownloadPdf" if u click this link it wl show one "save dialogue box" for that the code is below, try it....

protected void LinkButtonDownloadPdf_Click(object sender, EventArgs e)
{
        Response.ContentType = "Application/pdf";
        Response.AppendHeader("Content-Disposition", "attachment; filename=scan.pdf");
        Response.TransmitFile(Server.MapPath("scan.pdf"));
        Response.End(); 
}

here "scan.pdf" is pdf file name...

Thanks...
 
Share this answer
 

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