Due to increased security in UR7, the CRM SDK Sample code for downloading attachments no longer works. We'll be releasing an SDK update before the end of November with a complete sample and documentation for this. However, here is a sample snippet you can use now:
For salesliterature, “annotation” should be changed to “salesliterature” and “EntityName.annotation” to “EntityName.salesliterature”, everything else stays the same.
For Mail Merge Templates and Activity Mime Attachments (email attachments), “documentbody” will change to “body” and object names should change correspondingly.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "<<MyOrgName>>";
CrmService service = new CrmService();
service.Url = "http://<<MyServerName>>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
annotation attachment = (annotation)service.Retrieve(EntityName.annotation.ToString(), new Guid("<<AttachmentGuid>>"), new ColumnSet(new string[] { "filename", "documentbody", "mimetype" }));
using (FileStream fileStream = new FileStream(attachment.filename, FileMode.OpenOrCreate))
{
byte[] fileContent = Convert.FromBase64String(attachment.documentbody);
fileStream.Write(fileContent, 0, fileContent.Length);
}