I am downloading the word file for GetSourceAttachment method. When this method returns empty bytes then my byte Attachment array gives an error:
Object reference not set instance of object
It gives the error when I check the length of Attachment in if condition.
Can any one help me to default initialize the byte array, then check the length?
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
{
}