博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MS CRM 2011 C#中获取Web Resource
阅读量:7135 次
发布时间:2019-06-28

本文共 2271 字,大约阅读时间需要 7 分钟。

我在以前的文章中讲过,我在本文中将要讲解如何在C#中获取web resource资源。

 

有时候可能有这样的需求,你需要在一个插件中读取某个xml web resource的内容,并将该xml文件作为附件创建一封E-mail。或者该xml文档是插件的一个配置文件。这时,你就需要在C#中获取web resource资源了。CRM中web resource不过是一个特殊的entity,在数据库中你也可以看到web resource table。web resource的内容(content)以Base64编码保存在数据库中(参见)。你只需要知道web resource的name,然后就可以用RetrieveMultiple方法获取该web resource。下面的代码演示了,如何获取一个名为aw_testxml.xml的web resource,并将其内容作为附件发送给一封E-mail。

// Create an e-mail message.    // Create the 'From:' activity party for the email ActivityParty fromParty = new ActivityParty {     PartyId = new EntityReference(SystemUser.EntityLogicalName, new Guid("F6F5BB29-D519-E211-B109-B499BAFDBEDA")) };// Create the 'To:' activity party for the email ActivityParty toParty = new ActivityParty {     PartyId = new EntityReference(SystemUser.EntityLogicalName, new Guid("F6F5BB29-D519-E211-B109-B499BAFDBEDA")) };Email email = new Email {     To = new ActivityParty[] { toParty },     From = new ActivityParty[] { fromParty },     Subject = "SDK Sample e-mail",     Description = "SDK Sample for SendEmail Message.",     DirectionCode = true }; Guid _emailId = service.Create(email);QueryExpression mySavedQuery = new QueryExpression {     ColumnSet = new ColumnSet(true),     EntityName = WebResource.EntityLogicalName,     Criteria = new FilterExpression()     {         Conditions =         {                                    new ConditionExpression             {                 AttributeName = "name",                 Operator = ConditionOperator.Equal,                 Values = {
"aw_testxml.xml"} } } } };EntityCollection ec = service.RetrieveMultiple(mySavedQuery); if (ec != null && ec.Entities != null && ec.Entities.Count > 0) { WebResource webresource = ec.Entities[0].ToEntity
(); ActivityMimeAttachment _sampleAttachment = new ActivityMimeAttachment { ObjectId = new EntityReference(Email.EntityLogicalName, _emailId), ObjectTypeCode = Email.EntityLogicalName, Subject = "Sample Attachment", Body = webresource.Content, FileName = "ExampleAttachment.xml" }; service.Create(_sampleAttachment); }

 

本文转自JF Zhu博客园博客,原文链接:http://www.cnblogs.com/jfzhu/archive/2013/02/15/2913077.html    ,如需转载请自行联系原作者

你可能感兴趣的文章
Java 集合系列12之 TreeMap详细介绍(源码解析)和使用示例
查看>>
Gradle传给虚拟机的参数
查看>>
聊一聊RPC
查看>>
Redis 概念以及底层数据结构
查看>>
Docker容器中运行.Net Core应用程序
查看>>
通过mysql工具能连接上docker下的mysql,部署的工程连接就报错。
查看>>
兄dei,是时候给你的项目做一波优化了~
查看>>
数据库事务的方方面面
查看>>
Python爬虫实战之爬取链家广州房价_01简单的单页爬虫
查看>>
Chrome 性能监测
查看>>
LocalDateTime和Date互相转换
查看>>
基于Serverless架构最新应用场景详解
查看>>
[BTCC] 要“工程师”“工程师”“工程师”
查看>>
阻塞IO
查看>>
信用算力实现金融级数据服务的实践
查看>>
Xcode配置测试环境和线上环境
查看>>
三大主流软件负载均衡器对比(LVS 、 Nginx 、Haproxy)
查看>>
学习技能总结:
查看>>
高可用集群----理论
查看>>
backtrack两种开启ssh方式
查看>>