locked
attach file to existing opportunity RRS feed

  • Question

  • Hello,

    Let me start off by saying I've never used Microsoft CRM before and my company wants me to add something to it.  Here's what I need to do.  I need to add a custom aspx page that will create a file (I've already got this done) then I need the file to be attached to an existing opportunity in Microsoft CRM (version 4).  How can I do this?  Do I need to use the sdk for it?  Anyone have some sample code?

    Thanks.
    Monday, August 11, 2008 6:58 PM

Answers

  • You will need to use the SDK to attach the file. To attach a file, you will need to create an annotation for the entity that you want to attach the file to.

     

    You'll need to create an instance of the CRMService, and create an annotation similar to below:

     

    Code Snippet

    annotation anno = new annotation();

    anno.objectid = CrmTypes.CreateLookup(entityName, entityID);

    anno.mimetype = mimetype;

    anno.filename = filename;

    anno.filesize = filesize;

    anno.documentbody = documentbody;

    anno.objecttypecode = new EntityNameReference(entityName);

    anno.subject = "Subject of the attachment";

    anno.isdocument = new CrmBoolean(true);

    service.Create(anno);

     

     

    The document body needs to be encoded to a base64 string which can be done with System.Convert.ToBase64String

     

    Monday, August 11, 2008 9:16 PM

All replies

  • You will need to use the SDK to attach the file. To attach a file, you will need to create an annotation for the entity that you want to attach the file to.

     

    You'll need to create an instance of the CRMService, and create an annotation similar to below:

     

    Code Snippet

    annotation anno = new annotation();

    anno.objectid = CrmTypes.CreateLookup(entityName, entityID);

    anno.mimetype = mimetype;

    anno.filename = filename;

    anno.filesize = filesize;

    anno.documentbody = documentbody;

    anno.objecttypecode = new EntityNameReference(entityName);

    anno.subject = "Subject of the attachment";

    anno.isdocument = new CrmBoolean(true);

    service.Create(anno);

     

     

    The document body needs to be encoded to a base64 string which can be done with System.Convert.ToBase64String

     

    Monday, August 11, 2008 9:16 PM
  • Awesome!  Thanks a million! 
    Tuesday, August 12, 2008 12:39 PM