CRM 2011 CS: create request to retrieve Webresource


//create request to retrieve Webresource

            QueryByAttribute requestWebResource = new QueryByAttribute

            {

                EntityName = WebResource.EntityLogicalName,

                ColumnSet = new ColumnSet(true),

            };

 

            requestWebResource.Attributes.AddRange("name");

            requestWebResource.Values.AddRange("url/XML/TestData.xml");

            WebResource webResource = null;

            EntityCollection webResourceCollection = organizationService.RetrieveMultiple(requestWebResource);

            if (webResourceCollection.Entities.Count == 0)

            throw new InvalidPluginExecutionException("Specified Webresource does not exist");

                webResource = (WebResource)webResourceCollection.Entities[0];

           

            byte[] binary = Convert.FromBase64String(webResource.Attributes["content"].ToString());

           string resourceContent = UnicodeEncoding.UTF8.GetString(binary);