【问题标题】:Activated Solution on Sharepoint 2010 is not visibleSharepoint 2010 上的激活解决方案不可见
【发布时间】:2012-12-17 14:43:20
【问题描述】:

我已经激活了一个包含网站模板的 WSP 文件。这可行,我可以在解决方案库中看到解决方案。当我尝试基于该模板创建网站时,它没有显示出来。但它显示“状态:已激活”。

然后我尝试停用它并再次手动激活它。突然间,出现了一个新模板,它的名字是我的模板名称加上一个“2”。

那么这里到底发生了什么?激活我的解决方案的代码是:

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 { ... }

【问题讨论】:

    标签: sharepoint deployment solution


    【解决方案1】:

    好的,我自己找到了答案,想在这里分享。解决方法是,不提供目录中的解决方案,还要启用功能!它的工作原理是这样的:

    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 { ... }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 2011-08-09
      • 1970-01-01
      相关资源
      最近更新 更多