Reputation: 403
I want to be able to store newly created PDF in a BLOB field in my MySQL database. This is the code I have so far but it saves to local disk instead:
string fileName = employeeNo.ToString();
MemoryStream ms = new MemoryStream();
byte[] bits = new byte[0];
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, ms);
doc.Open();
iTextSharp.text.Rectangle rec2 = new iTextSharp.text.Rectangle(PageSize.A4);
doc.Add(new Paragraph(textBox2.Text));
doc.Add(new Paragraph(textBox1.Text));
doc.Close();
bits.ToArray();
How could I adapt this so that it can be inserted into my database instead? The file would then be passed into the insert statement as below:
myCmd.Parameters.AddWithValue("@feedbackComments", bits);
Upvotes: 1
Views: 1462
Reputation: 1916
Instead of a FileStream
use a MemoryStream
and extract the byte array with ToArray()
after closing the doc.
Use the byte array to populate the table.
Upvotes: 1