Microsoft > Dynamics Forums > CRM Development > New Sample Code for Downloading Attachments (post UR7)
Ask a questionAsk a question
 

General DiscussionNew Sample Code for Downloading Attachments (post UR7)

  • Friday, November 13, 2009 4:24 PMA Langlois - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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);
    }
     

All Replies

  • Tuesday, December 01, 2009 1:38 PMtoto2208 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Yes this way works for me.
    I found it by myself but I didnt know why download is not allowed.

    Thank you