Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written the following in a Windows C# application on the on_click event of a button:

C#
using System.IO;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;


Document myDocument = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);

PdfWriter.GetInstance(myDocument, new FileStream("C:\\IngenicoDetails", FileMode.Create));
myDocument.Open();
myDocument.Add(new Paragraph("ID:" + TextBox1.Text));

myDocument.Close(); 


How can I use a savedialog to specify the path and the filename, instead of hardcoding the Path and Filename?

Thanx
Posted

Try this:

C#
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "PDF Files|*.pdf";
dlg.FilterIndex = 0;

string  fileName = string.Empty;

if (dlg.ShowDialog() == DialogResult.OK) {
    fileName = dlg.FileName;
}


NOTE: Include the System.IO namespace;
 
Share this answer
 
Comments
JacoBosch 27-Feb-12 5:12am    
Thanx. I got it right. Thank you. I will post the whole code
C#
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "PDF Files|*.pdf";
dlg.FilterIndex = 0;

string fileName = string.Empty;

if (dlg.ShowDialog() == DialogResult.OK)
{
fileName = dlg.FileName;
           
Document myDocument = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);
PdfWriter.GetInstance(myDocument, new FileStream(fileName, FileMode.Create));
myDocument.Open();
myDocument.Add(new Paragraph("ID:" + TextBox1.Text));pre>
myDocument.Close();
}
 
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