I'm a crm newbie so forgive my misunderstandings or misadventures.
I'm trying to programmatically create a webresource (javascript or jscript to be precise) early bound using the OrganizationServiceproxy like this
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)
};
//context.AddObject(javascriptWebResource);
//context.SaveChanges();
service.Create(javascriptWebResource);
}
else
{
//update the webresource
}
My question is- do I need to set more Entity Metadata than what I'm currently setting to successfully create the web resource?
The creation code is not throwing any errors however I cannot find my newly created javascript webresource on the crm server in the specified solution. I guessed it was adding web resource to the default solution therefore I scoured the web and came across a sample in the sdk which goes like this
Guid theGuid = _serviceProxy.Create(wr);
//If not the "Default Solution", create a SolutionComponent to assure it gets
//associated with the ActiveSolution. Web Resources are automatically added
//as SolutionComponents to the Default Solution.
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);
}
My question is - if I retrieve the solutionuniquename then will it create the web resource in the appropriate solution and I would be able to see the javascript web resource on the crm server?
Thanks in advance for your help.