Search code examples
sharepointdeploymentsolution

Activated Solution on Sharepoint 2010 is not visible


I have activated a WSP file which includes a website template. This works and I can see the solution int he solution gallery. When I try to create a website, based on that template, its not showing up. But it says "Status: Activated".

Then I tried to deactivate it and activate it again manually. Out of a sudden, there is a new template showing up, which takes the name of my template appended by a "2".

So whats happening here exactly? The code to activate my solution is:

System.IO.MemoryStream input = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(rootDirectory + "\\Templates\\Project.wsp"), true);

SPDocumentLibrary solutionGallery = (SPDocumentLibrary)web.Site.GetCatalog(SPListTemplateType.SolutionCatalog);

try
{
 SPFile solutionFile = solutionGallery.RootFolder.Files.Add("Project.wsp", input);
 SPUserSolution newUserSolution = web.Site.Solutions.Add(solutionFile.Item.ID);
}
catch { ... }

Solution

  • Ok, I found the answer myself and want to share it here. The solution is, not to provide the solution in the catalog, but also to enable the features! It works like this:

    System.IO.MemoryStream input = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(rootDirectory + "\\Templates\\Project.wsp"), true);
    
    SPDocumentLibrary solutionGallery = (SPDocumentLibrary)web.Site.GetCatalog(SPListTemplateType.SolutionCatalog);
    
    try
    {
     SPFile solutionFile = solutionGallery.RootFolder.Files.Add("Project.wsp", input);
     SPUserSolution newUserSolution = web.Site.Solutions.Add(solutionFile.Item.ID);
    
     Guid solutionId = newUserSolution.SolutionId;
    
     SPFeatureDefinitionCollection siteFeatures = web.Site.FeatureDefinitions;
     var features = from SPFeatureDefinition f
                 in siteFeatures
                 where f.SolutionId.Equals(solutionId) && f.Scope == SPFeatureScope.Site
                 select f;
     foreach (SPFeatureDefinition feature in features)
     {
      try
      {
       web.Site.Features.Add(feature.Id, false, SPFeatureDefinitionScope.Site);
      }
      catch { }
     }
    
     SPWebTemplateCollection webTemplates = web.Site.RootWeb.GetAvailableWebTemplates(1033);
     SPWebTemplate webTemplate = (from SPWebTemplate t
                               in webTemplates
                               where t.Title == "Projekt"
                               select t).FirstOrDefault();
     if (webTemplate != null)
     {
      try
      {
       web.Site.RootWeb.ApplyWebTemplate(webTemplate.Name);
      }
      catch { }
     }
    }
    catch { ... }