我正在下载GetSourceAttachment
方法的word文件。当此方法返回空字节时,我的字节Attachment
数组会出错:
对象引用未设置对象实例
Attachment
当我检查inif
条件的长度时,它会给出错误。
谁能帮我默认初始化字节数组,然后检查长度?
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
{
}