Programmatic way to download CRM attachments

We have some sample code on this topic being released in the next rev of the SDK samples (coming very soon!). In the meantime, since I have been asked about this a few times, here is a simple piece of code that shows how to download CRM attachments using the .NET WebClient class. Needless to mention that Uploading attachments programmatically through web services is a new feature in CRM V3.0.

using System.Net;

//NOTE: AttachmentType represents the type of the attachment: 1001 for ActivityMimeAttachment, 5 for Annotation and 1070 for SalesLiteratureItem.

//This is the ID of the attachement that you are trying to download

string myAttachementId = "{00000000-0000-0000-0000-00000000000}";

string url = "https://localhost/Activities/Attachment/download.aspx?AttachmentType=5&AttachmentId=" + myAttachementId;

WebClient myWebClient = new WebClient();

myWebClient.Credentials = CredentialCache.DefaultCredentials;

myWebClient.DownloadFile(url,"C:\myfile");