Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

How To : Retrieve Web Resource Contents in Microsoft CRM 2011 in .NET

3 Comments

Hi, in this article i am gonna show how to retrieve the content of an “HTML Web Resource” in Microsoft Dynamics CRM 2011 by .Net

You need to perform 2 steps 

1. perform a “RetrieveMultiple” call to pull back your web resource entity.
2. Decode the “content” property from base-64 to a string.

code :

RetrieveMultipleRequest RetrieveWebResources= new RetrieveMultipleRequest();
RetrieveMultipleResponse resp = new RetrieveMultipleResponse();
Entity webresource = new Entity();

QueryExpression query = new QueryExpression()
{
EntityName = “webresource”,
ColumnSet = new ColumnSet(“content”),
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = “name”,
Operator = ConditionOperator.Equal,
Values = { “web resource name”}
}
}
}
};

RetrieveWebResources.Query = query;
resp = (RetrieveMultipleResponse)_serviceproxy.Execute(RetrieveWebResources);
webresource= resp.EntityCollection.Entities[0];

byte[] b = Convert.FromBase64String(webresource[“content”].ToString());

string strHTML = System.Text.Encoding.UTF8.GetString(b);

 

3 thoughts on “How To : Retrieve Web Resource Contents in Microsoft CRM 2011 in .NET

  1. Grate Post . . . .! ! ! !

  2. Hi , is it possible to retrieve Document attached in annotation Eg:( word , pdf) and to display as string .

Leave a reply to Michael Philip Cancel reply