segunda-feira, 12 de novembro de 2007

How to download CRM note's attachments

This is something I never needed to do until today and since the info we can get inside the SDK is not very detailed, here's a quick example:

annotation a = (annotation)service.Retrieve("annotation", new Guid("{56889D1A-6391-DC11-8017-000C2928380D}"), new AllColumns());

string myNote = "{56889D1A-6391-DC11-8017-000C2928380D}";
string url = "http://localhost:5555/Activities/Attachment/download.aspx?" + "AttachmentType=5&AttachmentId=" + myNote;

WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
myWebClient.DownloadFile(url,@"C:\CRM\" + a.filename );


Please note that you must change the Attachment Type according to the entity that owns the attachment:

  • 1001 for ActivityMimeAttachment (like email attachments),
  • 5 for Annotation (note's attachments) and
  • 1070 for SalesLiteratureItem.

Hope that will help.


PS: This is not a Titan CRM post yet.