我正在下载 GetSourceAttachment
方法的 Word 文件。当该方法返回空字节时,我的字节 Attachment
数组会出现错误:
对象引用未设置为对象的实例。
当我在 if
条件中检查 Attachment
的长度时,它会输出此错误。
是否有人可以帮我默认初始化字节数组,然后检查其长度?
try
{
byte[] Attachment = null ;
string Extension = string.Empty;
ClsPortalManager objPortalManager = new ClsPortalManager();
Attachment = objPortalManager.GetSourceAttachment(Convert.ToInt32(hdnSourceId.Value), out Extension);
if (Attachment.Length > 0 && Attachment != null)
{
DownloadAttachment("Attacment", Attachment, Extension);
}
else
{
ClientScript.RegisterStartupScript(typeof(Page), "SymbolError", "<script type='text/javascript'>alert('Attachment is not Uploaded !');</script>");
}
}
catch
{
}