0
votes

I want to download all documents from CRM 2011 (from every notes and email, basically I need each and every document) along with to a local windows folder.

Is there a custom C# code or powershell script to do this?

Kindly let me know if there are any open source tool or paid tools for doing this.

Thanks,

1

1 Answers

2
votes

You can write a simple piece of code to do this. Please see Exporting Annotation (Note) Attachment.

public void ExportDocuments(IOrganizationService service, String filePath)
{
     String fetch = @"<fetch mapping='logical' count='100' version='1.0'>
          <entity name='annotation'>
               <attribute name='filename' />
               <attribute name='documentbody' />
               <attribute name='mimetype' />
          </entity>
     </fetch>";

     foreach (Entity e in service.RetrieveMultiple(new FetchExpression(fetch)))
     {
          if (!String.IsNullOrWhiteSpace(e.Attributes["documentbody"].ToString()))
          {
               byte[] data = Convert.FromBase64String(e.Attributes["documentbody"].ToString());

               File.WriteAllBytes(filePath + e.Attributes["filename"].ToString(), data);
          }
     }
}