OPEN TO WORK

Available for new opportunities! Let's build something amazing together.

Deploying Branding Files Using a Sandbox Solution

Master Page Sandboxed
post

This post is over a year old, some of this information may be out of date.

When you want to create a SharePoint 2010 sandbox branding solution, you will notice that your files will be in draft (Checked out). This means that these files are not available yet for all users. Therefore two actions need to be done for each file:

  • Check in the file;
  • Approve the file. As an example I deployed a master page using a sandbox solution. When the solution is deployed and the feature is activated, the master page file has the following properties.
Show image Master Page in draft
Master Page in draft

As you can see the file is not checked in and the approval status is still draft.

Solution

A solution is to check in and approve the file when the feature is activated.

Create a feature event receiver for the feature that deploys the branding files (in this example this is a Site Collection feature), and write code for the FeatureActivated event.

The following code retrieves the file, checks it in, and approves it.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPSite site = (SPSite)properties.Feature.Parent)
using (SPWeb web = site.RootWeb)
{
// Set the master page url
string masterUrl = site.ServerRelativeUrl;
if (!masterUrl.EndsWith(@"/"))
{
masterUrl = masterUrl + @"/";
}
// Retrieve the file
SPFile file = web.GetFile(masterUrl + "_catalogs/masterpage/v4_estruyf.master");
// Check in the master page
file.CheckIn("Checked in by the branding feature.");
// Approve the master page
file.Approve("Approved by the branding feature.");
file.Update();
}
}

When the new solution is deployed, you will see that the file is now a major version and approved.

Show image Approved Master Page
Approved Master Page

Related articles

Report issues or make changes on GitHub

Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.

Comments

Elio Struyf

Solutions Architect & Developer Expert

Loading...

Let's build together

Manage content in VS Code

Present from VS Code