////// Reads the CRM Web Resource by its unique name as a string /// public string ReadContent(string resourceName) { byte[] byteArray = ReadBytes(resourceName); if (byteArray != null) { return System.Text.Encoding.UTF8.GetString(byteArray); } return string.Empty; } ////// Reads the CRM Web Resource by its unique name as a byte array /// public byte[] ReadBytes(string resourceName) { try { WebResource webResource = new WebResource(); 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 = { resourceName }} } } }; RetrieveMultipleRequest retrieveMultipleRequest = new RetrieveMultipleRequest { Query = query }; RetrieveMultipleResponse retrieveMultipleResponse = (RetrieveMultipleResponse)service.Execute(retrieveMultipleRequest); if (retrieveMultipleResponse != null && retrieveMultipleResponse.EntityCollection != null && retrieveMultipleResponse.EntityCollection.Entities.Count > 0) { webResource = (WebResource)retrieveMultipleResponse.EntityCollection.Entities[0]; byte[] byteArray = Convert.FromBase64String(webResource.Content); return byteArray; } } catch (Exception exception) { } return null; }
Tuesday, August 13, 2013
CRM 2011: How to read Web resource from code
Following code snippet will help you to read content of the web resource.
Subscribe to:
Posts (Atom)
MS CRM 2011 KB Article customization Issue.
Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form. 1. Add Ba...
-
Recently I wanted to find out users who are not in the correct time zone in CRM System. To change the time zone or user related settings we ...
-
If you want to take part in the internet as a business, information resource, directory, or as a hobbyist wanting to share data, informatio...
-
Do you need to recover lost files, photos or documents? You're sure that a file was on your hard disk some time ago, but now it seems to...