private void CreateWebResource(XElement webResourceInfo) { try { //Create the Web Resource. WebResource wr = new WebResource() { Content = getEncodedFileContents(ActivePackage.Attribute("rootPath").Value + webResourceInfo.Attribute("filePath").Value), DisplayName = webResourceInfo.Attribute("displayName").Value, Description = webResourceInfo.Attribute("description").Value, LogicalName = WebResource.EntityLogicalName, Name = GetWebResourceFullNameIncludingPrefix(webResourceInfo) }; wr.WebResourceType = new OptionSetValue((int)ResourceExtensions.ConvertStringExtension(webResourceInfo.Attribute("type").Value)); //Special cases attributes for different web resource types. switch (wr.WebResourceType.Value) { case (int)ResourceExtensions.WebResourceType.Silverlight: wr.SilverlightVersion = "4.0"; break; } // ActivePublisher.CustomizationPrefix + "_/" + ActivePackage.Attribute("name").Value + webResourceInfo.Attribute("name").Value.Replace("\\", "/"), 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); } } catch (Exception e) { AddMessage("Error: " + e.Message); return; } }
/// <summary> /// Create a new webressource /// </summary> /// <param name="webResourceInfo"></param> public Guid?Create(XElement webResourceInfo) { try { var type = (int)ResourceExtensions.ConvertStringExtension(webResourceInfo?.Attribute(WebResource.Type)?.Value); var optionsetValue = new OptionSetValue(type); var fullName = GetWebResourceFullNameIncludingPrefix(webResourceInfo); //Create the Web Resource. var wr = new Entities.WebResource { Content = GetEncodedFileContents(webResourceInfo?.Attribute(WebResource.FilePath)?.Value), DisplayName = webResourceInfo?.Attribute(WebResource.DisplayName)?.Value, Description = webResourceInfo?.Attribute(WebResource.Description)?.Value, LogicalName = Entities.WebResource.EntityLogicalName, Name = fullName, WebResourceType = optionsetValue }; var guid = Service.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") { var scRequest = new AddSolutionComponentRequest { ComponentType = (int)SolutionComponent.OptionSet.ComponentType.WebResource, SolutionUniqueName = ActiveSolution.UniqueName, ComponentId = guid }; Service.Execute(scRequest); } return(guid); } catch (Exception e) { err.Error("Error: " + e.Message); return(null); } }