问题
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);
回答1:
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.
来源:https://stackoverflow.com/questions/28647435/save-created-pdf-to-mysql-database-c-sharp