I use a feature to deploy a master page to a SharePoint 2010 publishing site. I use VS 2010 SharePoint projects. The feature deploys the .master , some CSS files and some images. Everything works OK except that all files deployed are in "Draft" state and I need to go and publish them manually.

What do I need to do so that when the feature is deployed, all the files are readily deployed as "published" ?


I think this caused by one of the fantastic gotchas in SP2010. That is... if your solution is a Sandboxed solution the files aren't checked in/approved automatically - but farm solutions do check in/approve them.

If you're in a Sandboxed solution, you have to do this process manually - see http://blog.mastykarz.nl/automatically-publishing-files-provisioned-sandboxed-solutions/ for a good write up.


When files get deployed through features they should be in approved state already! There is something else going on here. Could you check the ULS logs etc. to see in there's not something missing? Is the feature perhaps Web scoped instead of Site scoped (which it should be for at least master pages)? The Elements tag should be set to RootWebOnly i.e.:

<Module Name="NAME" Url="_catalogs/masterpage" Path="LOCALPATHINFEATURE" RootWebOnly="TRUE">


<Module Name="NAME" Url="Style Library/css" Path="LOCALPATHINFEATURE" RootWebOnly="TRUE">

When deploying master pages i use this feature event receiver to fix up the many possible things that can go wrong when deploying master pages via features.

public class LayoutsFeatureReceiver : Microsoft.SharePoint.SPFeatureReceiver {

    public override void FeatureActivated(SPFeatureReceiverProperties properties) {
        object parent = properties.Feature.Parent;
        if (parent is SPSite) {
            SPSite site = (SPSite)parent
            using (SPWeb web = site.RootWeb) {
                SPElementDefinitionCollection elementDefinitionCollection = properties.Definition.GetElementDefinitions(new CultureInfo(1033));
                foreach (SPElementDefinition elementDefinition in elementDefinitionCollection) {
                    XmlNode elementrootnode = elementDefinition.XmlDefinition;
                    _FeatureActivated(elementrootnode, properties.Feature.Definition.RootDirectory, web);

    public static void _FeatureActivated(XmlNode elementrootnode, string rootdirectory, SPWeb web) {
        XmlNamespaceManager ns = new XmlNamespaceManager(elementrootnode.OwnerDocument.NameTable);
        ns.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/");
        XmlNodeList nodes2 = elementrootnode.SelectNodes(".//sp:Property[@Name='FixUpFile']", ns);
        foreach (XmlNode node2 in nodes2) {
            bool yesno = node2.Attributes["Value"].Value == "TRUE";
            string name = node2.ParentNode.Attributes["Url"].Value;
            string url = node2.ParentNode.ParentNode.Attributes["Url"].Value + "/" + name;
            if (yesno) {
                SPFile file = web.GetFile(url);
                if (file.Exists) {
                    if (file.CheckOutStatus != SPFile.SPCheckOutStatus.None) {
                        try {
                        } catch (SPException ex) {
                            if (ex.ToString().IndexOf("You cannot discard check out because there is no checked in version of the document. Please delete this document instead.") != -1) {
                            } else {
                                throw ex;
                    if (file.CustomizedPageStatus == SPCustomizedPageStatus.Customized) {
                    if (file.CustomizedPageStatus == SPCustomizedPageStatus.None) {
                        string rawdata = Path.Combine(rootdirectory, url);
                        byte[] data = File.ReadAllBytes(rawdata);
                        if (data.Length == 0) {
                            data = new byte[1];
                        if (file.Item.ModerationInformation != null) {
                    file = web.GetFile(url);
                    if (file.CustomizedPageStatus != SPCustomizedPageStatus.Uncustomized) {
                        //err: failed to re-ghost page
                } else {
                    //err: file not provision'ed, most likely a user has created a file but not check'ed it in

Add the FixUpFile property to your master page element definition to trigger the fix up

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="MasterPagesModule" 
        <File Url="custom.master" 
            <Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;" />
            <Property Name="Title" Value="Custom master page." />
            <Property Name="FixUpFile" Value="TRUE" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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