這裏即時下載GetSourceAttachment方法的word文件。當這個方法返回空字節然後我的字節附件數組給出一個錯誤(對象引用沒有設置對象的實例)。當im檢查附件的長度,如果條件那麼它給予錯誤。任何人都可以幫助我默認初始化字節數組,然後檢查長度。如何檢查字節數組是否爲空?
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
{
}
感謝馬修·沃特森...... – SANDEEP 2013-05-10 06:21:09