This posting doesn’t actually have anything to do with stsadm (unless you count the fact that you need stsadm to install Features) but I figured I’d post this here regardless as I’ve seen a lot of questions out there regarding how to do this. My specific requirement was to remove the “Create Blog” button on the My Sites home page. There are two ways to accomplish this – one that’s supported and one that’s not. The easiest approach (and the unsupported approach) is to modify the default.aspx file located at “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SPSPERS”. In this file simply remove or comment out the CreateBlogButton web control (ID=“TBBCreateBlogButton”). Note that I don’t recommend doing this as modifying these files will violate your support with Microsoft but I figure it’s at least worth mentioning that it’s possible.

The other approach is to use a Feature. There’s a great article by Steve Peschka on customizing My Sites which explains how to do all of this. There’s also a template project which you can find on CodePlex. I used this project as a starting place and tweaked it to meet my needs. There’s three approaches you can take to remove the create blog button (I won’t bother to address the other customizations you can do as they are documented on the above sites and in the readme files provided with the download).

The first is to modify the master page and make the PlaceHolderMiniConsole control no longer visible. The problem with this approach is that it also hides any other buttons that may be loaded into this control. The second approach is to put some code into the master page in a server script tag – that code would then do a series of FindControl calls to get the TBBCreateBlogButton control and then hide it. The problem with this is that it requires you to make some web.config changes to allow code blocks – something I’d strongly recommend against doing unless you had no other choice. The third option (which is the one I took) is to have the MySiteCreatePart control look for and remove the button (again, using FindControl). The one downside of this is that the code to hide the button has to run every time the page is loaded.

There may be other ways to do this but I was not able to identify one. Just a quick overview of what Steve’s code is doing – there are three components: the first is the MySiteStaplee which contains the custom master page and the MySiteStaplee.xml file which has all the settings that the MySiteCreatePart code utilizies. The custom master page is exactly like the default master page with the addition of two lines – one registers the MySiteCreatePart web control and the other adds the web control to the page in the Head section (you can modify this further to your heart’s content). The second part is the MySiteStapler which simply associates the MySiteStaplee feature with the SPSPERS#0 site template (so when a site is created with this site template the MySiteStaplee feature will be activated). The third piece is the web control (MySiteCreatePart) which gets loaded up by the master page.

This approach of using a web control allows the code to manipulate the running page without having to embed server side script blocks which would open up security issues (note that this is a simple object inheriting from WebControl – it is not a WebPart object – it really is about as basic as you can get so it’s real easy to work with). And finally, there’s a web.config change that is necessary to mark the web control as a safe control. In order to do what I needed I had to modify the code that Steve provided.

The first thing I did was to clean it up a bit – I broke the main method into a couple of smaller methods to help in readability and I modified the code so that it properly disposed of the objects such as the SPLimitedWebPartManager object and the various WebPart objects (minor issue but this should help with memory management). The next thing I added was a new attribute to the MySiteStaplee.xml file. I wanted to make it so that I could control whether the button appeared or not via the XML file so I added a “removeBlogButton” attribute to the document element. This way the value can be changed in the future so that any new MySites created would reflect the change (to address existing MySites one would simply need to loop through all the sites and set a custom property to true or false (assuming of course that the feature has been installed)). With this attribute in place I was then able to set a property on the SPWeb object which I then check whenever the page is loaded. The final code changes I made was to support an additional action and handle deactivation of the feature – Steve’s version only allowed Delete, Move, Add, and SetProperties, but I needed to be able to do a Close as well so I added that logic in. I also wanted it so that if the MySiteStaplee feature was deactivated that the original master page would be reassociated so I added that code in. The other changes I made to the MySiteStaplee.xml file were to simply move a couple of web parts around.

Download the original version for additional examples (I also included the original version within my download). Feel free to download my version of the MySiteCreate Feature and let me know if you have any issues.

Update 1/15/2008: I’ve fixed the batch files and updated the FeatureActivating event so that it won’t activate the feature at the root site and in case it does it will only switch the master page if the template is SPSPERS.