locked
CRM 4.0 Add Attachment Documents RRS feed

  • Question

  • CRM 4.0
    I would like to know if it is possible to have a window that has a field that allows me to "Attach" multiple pdf documents?
    Thank you

    Tuesday, August 18, 2009 8:10 PM

Answers

  • Hi Matt,

    You need to write a custom app if you want to fulfill this requirement. Attachment store in CRM as Annotation. Here's some sample that I wrote for one of my clients. Hope it helps!

           private Guid CreateAttachment(Guid emailid, Guid assignmentid, String docName)
            {
                Guid attachmentid = Guid.Empty;
    
                try
                {
                    
    
                    string encodedData = System.Convert.ToBase64String(byteData);
    
                    PropertyCollection mimeproperties = new PropertyCollection();
    
                    Property activityid = new LookupProperty("activityid", new Lookup(EntityName.email.ToString(),emailid));
                    mimeproperties.Add(activityid);
    
                    Property body = new StringProperty("body", encodedData);
                    mimeproperties.Add(body);
    
                    Property mimetype = new StringProperty("mimetype", "application/pdf");
                    mimeproperties.Add(mimetype);
    
                    Property attachmentnumber = new CrmNumberProperty("attachmentnumber", new CrmNumber(1));
                    mimeproperties.Add(attachmentnumber);
    
                    Property filename = new StringProperty("filename", docName + ".pdf");
                    mimeproperties.Add(filename);
    
                    // Create Attachment
                    DynamicEntity mime = new DynamicEntity();
                    mime.Name = EntityName.activitymimeattachment.ToString();
                    mime.Properties = mimeproperties;
    
                    TargetCreateDynamic target = new TargetCreateDynamic();
                    target.Entity = mime;
    
                    CreateRequest request = new CreateRequest();
                    request.Target = target;
    
                    CreateResponse response = (CreateResponse)crmService.Execute(request);
    
                    attachmentid = response.id;
    
                }
                catch (Exception ex)
                {
                    log.Error("CreateAttachment [" + DateTime.Now.ToString() + "]" + ex.ToString());
                }
    
                return attachmentid;
            }

    Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.com
    Tuesday, August 18, 2009 8:45 PM
    Moderator

All replies

  • Hi, Matthews.

    It seems that there are no such inbox functionality so you can only develop it.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, August 18, 2009 8:30 PM
    Moderator
  • This was some sample code for 1.2.  You may be able to leverage some of this and with some changes, get it working in a 4.0 environment.
    Best Regards, Donna
    Tuesday, August 18, 2009 8:33 PM
  • Hi Matt,

    You need to write a custom app if you want to fulfill this requirement. Attachment store in CRM as Annotation. Here's some sample that I wrote for one of my clients. Hope it helps!

           private Guid CreateAttachment(Guid emailid, Guid assignmentid, String docName)
            {
                Guid attachmentid = Guid.Empty;
    
                try
                {
                    
    
                    string encodedData = System.Convert.ToBase64String(byteData);
    
                    PropertyCollection mimeproperties = new PropertyCollection();
    
                    Property activityid = new LookupProperty("activityid", new Lookup(EntityName.email.ToString(),emailid));
                    mimeproperties.Add(activityid);
    
                    Property body = new StringProperty("body", encodedData);
                    mimeproperties.Add(body);
    
                    Property mimetype = new StringProperty("mimetype", "application/pdf");
                    mimeproperties.Add(mimetype);
    
                    Property attachmentnumber = new CrmNumberProperty("attachmentnumber", new CrmNumber(1));
                    mimeproperties.Add(attachmentnumber);
    
                    Property filename = new StringProperty("filename", docName + ".pdf");
                    mimeproperties.Add(filename);
    
                    // Create Attachment
                    DynamicEntity mime = new DynamicEntity();
                    mime.Name = EntityName.activitymimeattachment.ToString();
                    mime.Properties = mimeproperties;
    
                    TargetCreateDynamic target = new TargetCreateDynamic();
                    target.Entity = mime;
    
                    CreateRequest request = new CreateRequest();
                    request.Target = target;
    
                    CreateResponse response = (CreateResponse)crmService.Execute(request);
    
                    attachmentid = response.id;
    
                }
                catch (Exception ex)
                {
                    log.Error("CreateAttachment [" + DateTime.Now.ToString() + "]" + ex.ToString());
                }
    
                return attachmentid;
            }

    Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.com
    Tuesday, August 18, 2009 8:45 PM
    Moderator