0

Web サイト テンプレートを含む WSP ファイルを有効にしました。これは機能し、ソリューション ギャラリーでソリューションを確認できます。そのテンプレートに基づいて Web サイトを作成しようとすると、表示されません。しかし、「ステータス: アクティブ化」と表示されます。

次に、手動で無効にして再度有効にしようとしました。突然、私のテンプレートの名前に「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 { ... }
4

1 に答える 1

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 { ... }
于 2012-12-18T15:09:49.990 に答える