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");
Comments
Anonymous
February 22, 2006
What we really want to do is email attachments programmatically. Is that easy to do?Anonymous
March 14, 2006
You can use the same code. Email attachements are saved as ActiviyMimeAttachements in CRM (use code 1001 as listed above).Anonymous
July 05, 2006
Hi,
I have been trying to get some reference code on how to use the activitymimeattachment class to upload an attachment to a mail but have found anything. Any example code you can throw to the dogs? :)
GustafAnonymous
July 12, 2006
We have a good sample in the SDK docs. Download the latest SDK from the link on my recent blogs. After install go here:
<your install location?sdk samplesreferencecrmserviceapimiscellaneousuploadactivitymimeattachmentfrombase64data.csAnonymous
July 24, 2006
i got a 401 error when doing this from an application.
i did not use the default credential though, i use a new networkcredential object to pass my user-passwd-domain to the server.
any hint on this?Anonymous
July 25, 2006
Can you access any of the CRM web services or application from that machine? If you want to impersonate, use the callerID header that is explained in the SDK documents (link in my blog). Thanks ArashAnonymous
May 31, 2007
Hi ArashSichanie,You Help me a lot!but , If a annotation have 2 or more attachments?there is a to choose wich one download?Anonymous
May 31, 2007
Hey , Thx , I missread it ehhe , just choose the right guidAnonymous
June 18, 2008
thank you dude thats workmany thanks