Sharepoint 2010上的激活解决方案不可见

时间:2012-12-17 14:43:21

标签: sharepoint deployment solution

我已激活包含网站模板的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 { ... }

1 个答案:

答案 0 :(得分:0)

好的,我自己找到了答案并希望在此分享。解决方案是,不是在目录中提供解决方案,而是为了启用这些功能!它的工作原理如下:

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