CRM2013爲Email實體添加Excel附件

CRM2013使用代碼爲Email實體添加Excel附件

Workflow使用:

  private void addAttachment(Guid emailId, List<string> excel, IOrganizationService service)
        {
            Entity attachmentEntity = new Entity("activitymimeattachment");
            string strPath = excel[1];//Excel 文件包含地址
            var extension = Path.GetExtension(strPath).ToLower();//截取文件後綴名
            string attachmentName = Path.GetFileName(strPath);//文件名稱(包含後綴)
            switch (extension)
            {
                case ".xls":
                    attachmentEntity.Attributes["mimetype"] = "application/vnd.ms-excel";
                    break;
                case ".xlsx":
                    attachmentEntity.Attributes["mimetype"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    break;
            }
            attachmentEntity.Attributes["subject"] = "";
            attachmentEntity.Attributes["filename"] = attachmentName;//附件名稱
            attachmentEntity.Attributes["body"] = excel[0];//Excel 內容二進制流
            attachmentEntity.Attributes["objectid"] = new EntityReference("email", emailId);
            attachmentEntity.Attributes["objecttypecode"] = "email";
            service.Create(attachmentEntity);
        }

JavaScript使用:

需要使用XrmServiceToolkit
 
     var rfiAttachment = new XrmServiceToolkit.Soap.BusinessEntity("activitymimeattachment");
    rfiAttachment.attributes["subject"] = "";
    rfiAttachment.attributes["filename"] = rfiFileName;//附件名稱
    rfiAttachment.attributes["body"] = resultRfi[0];//Excel內容二進制流
    rfiAttachment.attributes["mimetype"] = "application/vnd.ms-excel";
    rfiAttachment.attributes["objectid"] = { id: rfiEmailId, logicalName: "email", type: "EntityReference" };
    rfiAttachment.attributes["objecttypecode"] = "email";
    XrmServiceToolkit.Soap.Create(rfiAttachment);



發佈了32 篇原創文章 · 獲贊 5 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章