Archive for February 2016

How To Add a Feature Stapler to My Sites and Change the Blog Title   Leave a comment

I’ve been working with SharePoint 2013 for some time now and now eagerly reviewing the new SharePoint 2016.  I noticed that when users provision their Blogs on their My Sites, the title default to “Welcome to My Blog”.  The eventual result of this becomes more apparent when they show up in the search results.

Here I decided to incorporate a feature stapler while working on a custom branded My Sites Masterpage.  This feature will, when a My Site Blog is provisioned, renames the Blog Title to “Welcome to <DisplayName>’s Blog.  Now when you search on Blogs it makes it more clear as to who blog it is.

So I in my Visual Studio Project, I created an Event Handler called “MySiteWebProvisioning” with the following code:

Imports System
Imports System.Security.Permissions
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.Workflow
Imports Microsoft.Office.Server

Public Class MySiteWebProvisioning
Inherits SPWebEventReceiver

”’ <summary>
”’ A site was provisioned.
”’ </summary>
Public Overrides Sub WebProvisioned(properties As SPWebEventProperties)
MyBase.WebProvisioned(properties)

Using targetWeb As SPWeb = properties.Web
Using rootWeb As SPWeb = targetWeb.Site.RootWeb

‘******************************************************************************************
‘* Set MySite Blog Title to Display Name’s – Blog.  When these MySite Blogs
‘* are Crawled, they will have return “User DisplayName’s – Blog rather than just “Blog".
'******************************************************************************************

If properties.Web.Site.HostName = “mysites.portal.contoso.com” Then
If properties.Web.WebTemplateId = “9” Then

Try
Dim spResource As SPUserResource = properties.Web.TitleResource
Dim sWebUrl As String = properties.ServerRelativeUrl
Dim sUserDisplayName As String = properties.UserDisplayName

properties.Web.Title = sUserDisplayName + “‘s – Blog”
properties.Web.AllowUnsafeUpdates = True
properties.Web.Update()

Catch ex As Exception
‘Throw a message in the ULS Logging
Microsoft.Office.Server.Diagnostics.PortalLog.LogString(“Exception Occurred Ascii.SP.ER.MySiteBranding: {0} || {1}”, ex.Message, ex.StackTrace)
End Try
End If
End If

‘Update Blog MasterPage
targetWeb.MasterUrl = rootWeb.MasterUrl
targetWeb.CustomMasterUrl = rootWeb.CustomMasterUrl
targetWeb.SiteLogoUrl = rootWeb.SiteLogoUrl
targetWeb.AlternateCssUrl = rootWeb.AlternateCssUrl
targetWeb.Update()

End Using

End Using

End Sub

End Class

Here is the Element.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
<Receivers >
<Receiver>
<Name>MySiteWebProvisioningWebProvisioned</Name>
<Type>WebProvisioned</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>Ascii.SP.ER.MySiteBranding.MySiteWebProvisioning</Class>
<SequenceNumber>10002</SequenceNumber>
</Receiver>
</Receivers>
</Elements>

In my Feature Stapler, I associated it with the MySite Template.  The Elements.xml for this is displayed below:

Elements.xml

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
<FeatureSiteTemplateAssociation Id=”c4c9b0b4-c604-4ec0-8355-3136fd02411b” TemplateName=”SPSPERS#2″ />
</Elements>

Happy SharePointing!

Posted February 2, 2016 by Bismarck in SharePoint 2013, SharePoint 2016