我有这个代码工作,它将PDF文档上传到SQL Server express,并将其显示给DataGridView。如何下载或查看(默认为 pdf 阅读器)上传的文件?
我发现的大多数代码片段都是针对 ASP.NET 的;这是Winforms。谢谢你。
private void btnSave_Click(object sender, EventArgs e)
{
if (docnoTextBox.Text == "" && docfromTextBox.Text == "")
{
MessageBox.Show("Cannot save empty strings");
}
else
{
try
{
iteisDataContext das_db = new iteisDataContext();
Document newDoc = new Document();
newDoc.docid = docnoTextBox.Text;
newDoc.docdate = docdateDateTimePicker.Value;
newDoc.postdate = DateTime.Now;
newDoc.doctype = cboDocType.Text;
newDoc.docfrom = docfromTextBox.Text;
//Convert string to linq.binary
Binary pdfFile = new ASCIIEncoding().GetBytes(ofdMain.FileName);
// And back to string - dae pa ini confirmado!
//string fileUpload = Encoding.ASCII.GetString(pdfFile.ToArray());
newDoc.docupload = pdfFile;
newDoc.docsubject = docsubjectTextBox.Text;
newDoc.notes = notesTextBox.Text;
// Update database
das_db.Documents.InsertOnSubmit(newDoc);
das_db.SubmitChanges();
MessageBox.Show("Document Saved.", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}