I'm relatively new to CRM, so please bear with me as I may make some mistakes along the way.
Currently, I am attempting to dynamically generate a web resource (specifically in JavaScript or JScript) early bound using OrganizationServiceproxy in the following manner:
var context = new OrganizationServiceContext(service);
var resource = (from wr in context.CreateQuery<WebResource>()
where wr.Name == name && wr.ComponentState.Value == 0
select wr).FirstOrDefault();
if (resource == null)
{
WebResource javascriptWebResource = new WebResource()
{
Name = name,
Description = name,
LogicalName = name,
DisplayName = value,
Content = Convert.ToBase64String(fileBytes),
WebResourceType = new OptionSetValue(3)
};
service.Create(javascriptWebResource);
}
else
{
//update the web resource
}
My question is - do I need to provide additional Entity Metadata in order to successfully create the web resource?
Although there are no errors being thrown during creation, I am unable to locate the newly created JavaScript web resource within the specified solution on the CRM server. I suspect it might have been added to the default solution, which led me to explore a sample solution from the SDK that looks like this:
Guid theGuid = _serviceProxy.Create(wr);
//If not the "Default Solution", create a SolutionComponent to ensure it is associated with the ActiveSolution.
if (ActiveSolution.UniqueName != "Default")
{
AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest();
scRequest.ComponentType = (int)componenttype.WebResource;
scRequest.SolutionUniqueName = ActiveSolution.UniqueName;
scRequest.ComponentId = theGuid;
var response = (AddSolutionComponentResponse)_serviceProxy.Execute(scRequest);
}
So my question remains - will retrieving the solution unique name solve the issue of creating the web resource in the correct solution and making the JavaScript web resource visible on the CRM server?
Thank you in advance for your assistance.