简体   繁体   中英

SharePoint 2010 - Approve / Publish files after deploying MasterPage solution

I've managed to deploy a new master page via a feature developed in Visual Studio (as per Deploying a custom master page in SharePoint 2010 ). However, while the files are copied to the SharePoint site, they are in 'draft' status, so as a result the new MasterPage won't work for regular users until the files have been approved/published.

Originally when the feature is activated, the MasterPage is set to the new MasterPage, but because of the 'draft' status, I had to turn off that functionality. That means I have to activate, then publish each file, which is cumbersome, especially if I want to apply it to more than one site and I ever update the MasterPage or related files.

How can I auto-publish the files that have been deployed as part of the solution. Through code (C# FeatureActivated ) I presume, since I haven't seen any xml attributes I can use in the elements.xml that can do this.

Additionally, after removing the solution, is it possible to delete the files from the site as well (the MasterPage is set back to its previous setting when the feature is deactivated)?

Please see my answer at SharePoint.SE .

The LayoutsFeatureReceiver

For deleting, implement the FeatureDeactivated event, and use

file.RevertContentStream();

to undo any edits to existing layouts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM