Dynamics CRM邮件附件,你真的了解吗?



static void Main(string[] args)
{
var service = GetOrganizationService();
var fetchXML = string.Format(@"<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false' no-lock='true' count='1'>
<entity name='email'>
<attribute name='subject' />
<attribute name='regardingobjectid' />
<attribute name='from' />
<attribute name='to' />
<attribute name='statuscode' />
<attribute name='activityid' />
<filter type='and'>
<condition value='微软MVP罗勇测试附件的邮件主题' attribute='subject' operator='eq' />
</filter>
</entity>
</fetch>");
EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetchXML));
if (ec.Entities.Count == )
{
Console.WriteLine("邮件的ID是" + ec.Entities[].GetAttributeValue<Guid>("activityid") + "下面是附件信息:");
QueryExpression query = new QueryExpression
{
EntityName = "activitymimeattachment",
ColumnSet = new ColumnSet("filename","subject","filesize","mimetype","activityid","activitymimeattachmentid","body"),
Criteria =
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "objecttypecode",
Operator = ConditionOperator.Equal,
Values = {"email"}
},
new ConditionExpression
{
AttributeName = "objectid",
Operator = ConditionOperator.Equal,
Values = {ec.Entities[].GetAttributeValue<Guid>("activityid")}
}
}
}
};
var i = ;
foreach (var entity in service.RetrieveMultiple(query).Entities)
{
Console.WriteLine("第" + i + "个附件:");
Console.WriteLine("filename:" + entity.GetAttributeValue<string>("filename"));
Console.WriteLine("filesize:" + entity.GetAttributeValue<int>("filesize"));
Console.WriteLine("mimetype:" + entity.GetAttributeValue<string>("mimetype"));
Console.WriteLine("subject:" + entity.GetAttributeValue<string>("subject"));
Console.WriteLine("activityid:" + entity.GetAttributeValue<EntityReference>("activityid").Id);
Console.WriteLine("activitymimeattachmentid:" + entity.GetAttributeValue<Guid>("activitymimeattachmentid"));
Console.WriteLine("body:" + entity.GetAttributeValue<string>("body"));
Console.WriteLine("--------------------------------------------------"); i++;
}
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}
运行结果如下,可以得知filesize应该是以字节为单位的,附件的内容应该是以base64编码后存储等等信息:


static void Main(string[] args)
{
var service = GetOrganizationService();
var fetchXML = string.Format(@"<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false' no-lock='true' count='1'>
<entity name='email'>
<attribute name='subject' />
<attribute name='regardingobjectid' />
<attribute name='from' />
<attribute name='to' />
<attribute name='statuscode' />
<attribute name='activityid' />
<filter type='and'>
<condition value='微软MVP罗勇测试附件的邮件主题' attribute='subject' operator='eq' />
</filter>
</entity>
</fetch>");
EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetchXML));
if (ec.Entities.Count == )
{
Console.WriteLine("邮件的ID是" + ec.Entities[].GetAttributeValue<Guid>("activityid") + "下面是附件信息:");
QueryExpression query = new QueryExpression
{
EntityName = "activitymimeattachment",
ColumnSet = new ColumnSet("filename","subject","filesize","mimetype","activityid","activitymimeattachmentid"),
Criteria =
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "activityid",
Operator = ConditionOperator.Equal,
Values = {ec.Entities[].GetAttributeValue<Guid>("activityid")}
}
}
}
};
var i = ;
foreach (var entity in service.RetrieveMultiple(query).Entities)
{
Console.WriteLine("第" + i + "个附件:");
Console.WriteLine("filename:" + entity.GetAttributeValue<string>("filename"));
Console.WriteLine("filesize:" + entity.GetAttributeValue<int>("filesize"));
Console.WriteLine("mimetype:" + entity.GetAttributeValue<string>("mimetype"));
Console.WriteLine("subject:" + entity.GetAttributeValue<string>("subject"));
Console.WriteLine("activityid:" + entity.GetAttributeValue<EntityReference>("activityid").Id);
Console.WriteLine("activitymimeattachmentid:" + entity.GetAttributeValue<Guid>("activitymimeattachmentid"));
Console.WriteLine("--------------------------------------------------");
i++;
}
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}
static void Main(string[] args)
{
var service = GetOrganizationService();
WhoAmIRequest whoAmIRequest = new WhoAmIRequest();
WhoAmIResponse whoAmIResponse = service.Execute(whoAmIRequest) as WhoAmIResponse;
Entity fromEntity = new Entity("activityparty");
fromEntity["partyid"] = new EntityReference("systemuser", whoAmIResponse.UserId);
Entity toEntity = new Entity("activityparty");
toEntity["partyid"] = new EntityReference("account", new Guid("858AB47F-494A-E511-80D2-000D3A802FAC"));
Entity emailEntity = new Entity("email");
emailEntity["to"] = new Entity[] { toEntity };
emailEntity["from"] = new Entity[] { fromEntity };
emailEntity["subject"] = "微软MVP罗勇测试邮件使用现有附件";
emailEntity["description"] = "<a href='http://sugege.top'>素格格新疆特产店</a>";
var emailId = service.Create(emailEntity);
var activityMimeAttachment = new Entity("activitymimeattachment");
activityMimeAttachment["objectid"] = new EntityReference("email",emailId);
activityMimeAttachment["objecttypecode"] = "email";
activityMimeAttachment["filename"] = "sugege.png";//不设置这个字段的值,附件不会显示文件名
activityMimeAttachment["filesize"] = ;//设置了这个字段的值,附件也不会显示文件大小(字节),囧
activityMimeAttachment["attachmentid"] = new Guid("b8ef5a55-1872-e511-80e6-000d3a804b9b");//该字段不能使用new EntityReference类型来赋值
service.Create(activityMimeAttachment);
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}

但是我如果查询这个邮件的附件信息会发现有点儿不同,比如filesize为0,mimetype为空值,囧。

static void Main(string[] args)
{
var service = GetOrganizationService();
WhoAmIRequest whoAmIRequest = new WhoAmIRequest();
WhoAmIResponse whoAmIResponse = service.Execute(whoAmIRequest) as WhoAmIResponse;
Entity fromEntity = new Entity("activityparty");
fromEntity["partyid"] = new EntityReference("systemuser", whoAmIResponse.UserId);
Entity toEntity = new Entity("activityparty");
toEntity["partyid"] = new EntityReference("account", new Guid("858AB47F-494A-E511-80D2-000D3A802FAC"));
Entity emailEntity = new Entity("email");
emailEntity["to"] = new Entity[] { toEntity };
emailEntity["from"] = new Entity[] { fromEntity };
emailEntity["subject"] = "微软MVP罗勇测试邮件使用新附件";
emailEntity["description"] = "<a href='http://sugege.top'>素格格新疆特产店</a>";
var emailId = service.Create(emailEntity);
var activityMimeAttachment = new Entity("activitymimeattachment");
activityMimeAttachment["objectid"] = new EntityReference("email", emailId);
activityMimeAttachment["objecttypecode"] = "email";
activityMimeAttachment["subject"] = "附件示例";
activityMimeAttachment["filename"] = "mvpluoyong.txt";//不设置这个字段的值,附件不会显示文件名
activityMimeAttachment["body"] = System.Convert.ToBase64String(new UTF8Encoding().GetBytes(@"微软MVP罗勇测试邮件使用新附件"));
service.Create(activityMimeAttachment);
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}


Dynamics CRM邮件附件,你真的了解吗?的更多相关文章
- dynamics crm 365 附件上传图片并且显示。
参考了几篇博客做的: 新增websource文件(html): <!DOCTYPE html> <html> <head> <title>注释</ ...
- Dynamics CRM中的注释(Note)及RollupRequest消息初探
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复161或者20151015可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 注释,这个实体的架构名称是Ann ...
- Dynamics CRM 2013开始推出的服务器端同步来配置邮件服务
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- 为Dynamics CRM的Office附件注释定制个无需下载即可在线查看的功能
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复164或者20151021可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 上一篇博客:为Dynamics ...
- 为Dynamics CRM注释的图片附件做个预览功能
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复163或者20151017可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! Dynamics CRM中注释可 ...
- Dynamics CRM 2016 的新特性
新版本CRM (2016 with update 0.1) 发布已有几个月了,总结一下新特性,从几个方面来看: 1. 针对整合功能的新特性 (1) 增加了CRM App for Outlook. 这个 ...
- Dynamics CRM中的操作(action)是否是一个事务(transaction)?
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复168或者20151104可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 以前的博文 微软Dynamics ...
- C# MailMessage Attachment 中文名附件发邮件-Firefox中文显示正常,网页打开邮件附件中文名乱码
一.故事 首先通过CDO.Message来获取邮件EML相关数据:邮件标题.邮件内容.邮件附件.发件人.收件人.CC主要就这么几个,其次通过MailMessage来组织邮件通过Python来发送邮件! ...
- Dynamics CRM模拟OAuth请求获得Token后在外部调用Web API
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复233或者20161104可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...
随机推荐
- JS---封装缓动(变速)动画函数---增加任意一个属性
封装缓动(变速)动画---增加任意一个属性 1. 本来的变速动画函数,是获取特定的属性(之前案例是向右移动,所以获取的是left属性) 2. 现在改变为,获取任意一个属性,使其移动到指定的target ...
- node.js+mysql用户的注册登录验证
下面代码实现的功能是:用node.js连接mysql实现用户的注册和登录,这里主要实现的是后端的验证代码,前端显示部分没具体写出. 整个程序的流程是这样的: 1.首先建立数据库reji,数据表user ...
- glusterFS空间不够了怎么办
查看glusterFS情况 oc project infra-storage oc get all #找到其中一个pod,前缀为 po/glusterfs-registry-xxxx oc exec ...
- 老版本nginx存在安全漏洞,不停服务热升级
1.场景描述 安全部通知:nginx存在"整数溢出漏洞",经测试2017年4月21日之后的版本无问题,将openresty升级到最新版本,Nginx升级到1.13.2之后的版本. ...
- Redis 数据淘汰机制
为了更好的利用内存,使Redis存储的都是缓存的热点数据,Redis设计了相应的内存淘汰机制(也叫做缓存淘汰机制) 通过maxmemory 配置项来设置允许用户使用的最大内存大小,当内存数据集大小达到 ...
- Dynamics CRM 2013开始推出的服务器端同步来配置邮件服务
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- HTTP Error 500.19 - Internal Server Error 无法读取配置文件
将Code移动文件夹就报以下错误,http error 500.19 - internal server error. 项目文件下.vs=>config=>applicationhost. ...
- ksoap2 android 调用WebService
webService,soap,wsdl的基本概念? 详情请看维基百科 基于soap 1.1, soap 1.2 的请求和响应数据源 查找了很久都是基于json格式传输数据,但是最终还是找到了基于xm ...
- 一、VUE项目BaseCms系列文章:项目介绍与环境配置
一.项目效果图预览: 二.项目介绍 基于 elementui 写一个自己的管理后台.这个系列文章的目的就是记录自己搭建整个管理后台的过程,希望能帮助到那些入门 vue + elementui 开发的小 ...
- MySQL能否授予查看存储过程定义权限给用户
在其他RDBMS中,可以将查看某个存储过程(PROCEDURE)定义的权限给某个用户,例如在SQL Server中,可以单独将查看ProcedureName定义的权限授予UserA GRANT VIE ...