2012-12-17 3 views
0

웹 사이트 템플릿이 포함 된 WSP 파일을 활성화했습니다. 이것은 작동하며 솔루션 갤러리를 볼 수 있습니다. 해당 템플릿을 기반으로 웹 사이트를 만들려고 할 때 웹 사이트가 표시되지 않습니다. 하지만 "Status : Activated"라고 적혀 있습니다.Sharepoint 2010의 활성화 된 솔루션이 표시되지 않습니다.

그런 다음 비활성화하고 수동으로 다시 활성화하려고했습니다. 갑자기 새로운 템플릿이 나타나는데, 템플릿의 이름에 "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 { ... } 

답변

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