2

I'm deploying a composed look from the server (including the .spcolor, .spfont, master.html and master.preview files), but I cannot get the field Associated File to select. I've tried setting it in just the elements.xml file as well as the event receiver's FeatureActivated event.

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>

And the code-behind:

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

Note: I've left out other irrelevant code.

2
  • Just to verify, are you calling page.Update() in your event receiver code? May 30, 2014 at 16:04
  • Yes, page.Update() is being called. I forgot to include that line. Am I missing something blatantly obvious?
    – psdpainter
    May 30, 2014 at 16:25

1 Answer 1

1

Ok so apparently trying to set the field HtmlDesignAssociated from the elements.xml file in a Module won't work.

Once I took that out, the code in the event receiver worked and my master.html file now has an associated master.master.

I modified the code a little to utilize SPUrlUtility.CombineUrl instead of web.GetList or web.Lists.TryGetList("whatever"). Here's the code that works:

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();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.