Domanda

Sto distribuendo un aspetto composto dal server (inclusi i file .spcolor, .spfont, master.html e master.preview), ma non riesco a selezionare il campo File associato.Ho provato a impostarlo solo in elements.xml file così come quello del destinatario dell'evento FeatureActivated evento.

Elementi.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>

E il codice dietro:

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

Nota:Ho tralasciato altro codice irrilevante.

È stato utile?

Soluzione

Ok, a quanto pare sto cercando di impostare il campo HtmlDesignAssociated dal elements.xml file in un modulo non funzionerà.

Una volta estratto, il codice nel ricevitore eventi ha funzionato e my master.html il file ora ha un file associato master.master.

Ho modificato leggermente il codice per utilizzarlo SPUrlUtility.CombineUrl invece di web.GetList O web.Lists.TryGetList("whatever").Ecco il codice che funziona:

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();
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top