TechnoJay
TechnoJay

Reputation: 31

Is it possible to export attachments from Microsoft Dynamics CRM 4.0 to a local file system and record relevant metadata?

Upvotes: 2

Views: 2623

Answers (2)

James Wood
James Wood

Reputation: 17562

This is a 2011 version which should be largely backwards compatible and covers the major points.

http://woodsworkblog.wordpress.com/2012/07/28/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);
          }
     }
}

Upvotes: 0

Guido Preite
Guido Preite

Reputation: 15128

  • Yes, it is possible.
  • Yes, CRM 4.0 has API to access the data.
  • Yes, the Schema is straightforward and available on MSDN.
  • Yes, the attachments are stored inside the Annotation entity, documentbody field, data encoded as Base64 string.

Upvotes: 1

Related Questions