title: How to correctly create javascript webresource programmatically
body: <p>I'm a crm newbie so forgive my misunderstandings or misadventures.</p>
  
  <p>I'm trying to programmatically create a webresource (javascript or jscript to be precise) early bound using the OrganizationServiceproxy like this</p>
  
  <pre><code>          var context = new OrganizationServiceContext(service);
  
            var resource = (from wr in context.CreateQuery&lt;WebResource&gt;()
                            where wr.Name == name &amp;&amp; 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
                   }
  </code></pre>
  
  <p>My question is- do I need to set more Entity Metadata than what I'm currently setting to successfully create the web resource?</p>
  
  <p>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</p>
  
  <pre><code>  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);
                  }
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks in advance for your help.</p>