【发布时间】:2013-11-30 16:05:16
【问题描述】:
有一个小方法可以访问数据库并从 varbinary 列中检索 pdf 文档,然后将数据添加到其中。我想添加代码,以便如果找不到此文档(公司文具),则创建并返回一个新的空白文档。该方法可以返回 Byte[] 或 Stream。
问题是 else 子句中的变量“bytes”为空。
任何想法有什么问题吗?
private Byte[] GetBasePDF(Int32 AttachmentID)
{
Byte[] bytes = null;
DataTable dt = ServiceFactory
.GetService().Attachments_Get(AttachmentID, null, null);
if (dt != null && dt.Rows.Count > 0)
{
bytes = (Byte[])dt.Rows[0]["Data"];
}
else
{
// Create a new blank PDF document and return it as Byte[]
ITST.Document doc =
new ITST.Document(ITST.PageSize.A4, 50f, 50f, 25f, 25f);
MemoryStream ms = new MemoryStream();
PdfCopy copy = new PdfCopy(doc, ms);
ms.Position = 0;
bytes = ms.ToArray();
}
return bytes;
}
【问题讨论】: