日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

MS CRM 2011 C#中获取Web Resource

發布時間:2023/12/9 C# 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MS CRM 2011 C#中获取Web Resource 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

原創地址:http://www.cnblogs.com/jfzhu/archive/2013/02/15/2913077.html

轉載請注明出處

?

我在以前的文章中講過如何用JScript讀取web resource資源,我在本文中將要講解如何在C#中獲取web resource資源。

?

有時候可能有這樣的需求,你需要在一個插件中讀取某個xml web resource的內容,并將該xml文件作為附件創建一封E-mail。或者該xml文檔是插件的一個配置文件。這時,你就需要在C#中獲取web resource資源了。CRM中web resource不過是一個特殊的entity,在數據庫中你也可以看到web resource table。web resource的內容(content)以Base64編碼保存在數據庫中(參見Base 64 Encoding 編碼)。你只需要知道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<WebResource>(); 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); }

?

總結

以上是生活随笔為你收集整理的MS CRM 2011 C#中获取Web Resource的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。