You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过CRM SDK获取Dynamics 365帖子和评论的附件内容

通过ActivityFileAttachment的FileContent GUID获取Dynamics 365附件内容

在Dynamics 365中,activityfileattachment实体的filecontent字段存储的不是文件内容本身,而是关联的annotation(注释)实体的ID。实际的文件内容、文件名、类型都存在annotation实体里,你需要通过这个GUID去查询annotation来获取附件数据。

具体步骤:

  1. 查询Annotation实体
    使用CRM SDK的RetrieveRequest或RetrieveMultipleRequest,传入filecontent对应的GUID,指定获取documentbody(文件内容)、filename(文件名)、mimetype(文件类型)这些核心属性。

    示例C#代码:

    // _serviceProxy 是已初始化的IOrganizationService实例
    Guid fileContentGuid = new Guid("你的filecontent字段值");
    
    var retrieveAnnotationRequest = new RetrieveRequest
    {
        Target = new EntityReference("annotation", fileContentGuid),
        ColumnSet = new ColumnSet("documentbody", "filename", "mimetype")
    };
    
    var response = (RetrieveResponse)_serviceProxy.Execute(retrieveAnnotationRequest);
    Annotation annotation = response.Entity.ToEntity<Annotation>();
    
  2. 解析文件内容
    annotation的documentbody字段是Base64编码的字符串,转成字节数组后即可保存为本地文件或进行其他处理:

    // 转成字节数组
    byte[] fileBytes = Convert.FromBase64String(annotation.DocumentBody);
    
    // 保存到本地
    File.WriteAllBytes($@"C:\temp\{annotation.FileName}", fileBytes);
    

补充说明:

  • fileattachment实体的处理逻辑和activityfileattachment完全一致,其关联的文件内容同样存储在annotation实体中。
  • 如果需要批量处理多个附件,可以用RetrieveMultipleRequest,过滤条件设为annotationid等于activityfileattachment的filecontent集合。

内容的提问来源于stack exchange,提问作者Akshar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 08:30:44