문제

서버에서 구성된 모양(.spcolor, .spfont, master.html 및 master.preview 파일 포함)을 배포하고 있지만 선택할 관련 파일 필드를 가져올 수 없습니다.나는 그것을 단지에 설정하려고 노력했다. elements.xml 파일 및 이벤트 수신자의 FeatureActivated 이벤트.

Elements.xml:

<File Path="Master\corporate.html" Url="corporate.html" Type="GhostableInLibrary" ReplaceContent="True">
  <Property Name="ContentType" Value="Html Master Page"></Property>
  <Property Name="UIVersion" Value="15"></Property>
  <Property Name="HtmlDesignAssociated" Value="TRUE"></Property>
  <Property Name="FSObjType" Value="0"></Property>
</File>

그리고 코드 숨김은 다음과 같습니다.

SPList masterGallery = web.Lists.TryGetList("Master Page Gallery");
SPListItemCollection masterItems = masterGallery.Items;

for (int m = 0; m < masterItems.Count; m++)
{
    SPListItem page = masterItems[m];
    if(page["Name"].ToString() == "corporate.html")
    {
        page["HtmlDesignAssociated"] = true;
        page.Update(); // forgot to include this line
    }
}

메모:관련없는 다른 코드를 생략했습니다.

도움이 되었습니까?

해결책

좋아, 분명히 필드를 설정하려고 하는 것 같군 HtmlDesignAssociated ~로부터 elements.xml 모듈의 파일이 작동하지 않습니다.

그것을 꺼내자 이벤트 수신기의 코드가 작동했고 내 master.html 이제 파일에 연결된 master.master.

활용하기 위해 코드를 약간 수정했습니다. SPUrlUtility.CombineUrl 대신에 web.GetList 또는 web.Lists.TryGetList("whatever").작동하는 코드는 다음과 같습니다.

var masterGallery = SPUrlUtility.CombineUrl(relativePath, "_catalogs/masterpage");
SPList master = web.GetList(masterGallery);
SPListItemCollection masterItems = master.Items;

for (int m = 0; m < masterItems.Count; m++)
{
    SPListItem page = masterItems[m];
    if (page["Name"].ToString() == "corporate.html")
    {
        page["HtmlDesignAssociated"] = true;
        page.Update();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top