Search code examples
dynamics-crmattachmentdynamics-crm-4

Programatically retrieve an attachment stored on a note on a CRM 4.0 entity


How would you suggest working with files that is stored on the note of a entity in Crm. Could you write a generic method that will enable you to access any type of file? Or would it be better to have a method for dealing with each type of file?

For example, we are going to be saving a mix of swf files and xml files on the entity, so would it make sense to have a method each for example:

  • GetXmlFilesOnAccount(accountid)
  • GetSwfFilesOnAccount(accountid)

Solution

  • My suggestion using your methods:

    * GetXmlFilesOnAccount(accountid)
    * GetSwfFilesOnAccount(accountid)
    
    1. Retrieve account activitypointers by regardingobjectid(in your case accountid guid)
    2. Loop through returned activitypointers
    3. Get attachments for each activitypointer (activitypointer.activityid = activitymimeattachment.activityid)
    4. Store attachments (disk, etc)

    You don't even need two methods. You can retrieve all attachment file types for a given note (annotation) with a single method.

    Hope this helps.