Tuesday 20 December 2016

SharePoint 2013 ::: How to restore the deleted "Suggested sites to follow" Web Part from a user's MySite

Hi all,

Today’s challenge is to restore the Web Part “Suggested sites to follow” that was deleted by the user himself.

So, do not lose your time in trying to find the Web Part in the Add Web Part page of the mySite, it is not available.



The script, provided by Microsoft, that put me on the track is:

Add-PsSnapin Microsoft.SharePoint.PowerShell
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.WebPartPages")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")

$useraccount = "useraccount"
$url = "http://" + [System.Net.Dns]::GetHostName() + "/my/personal/" + $useraccount
$site = get-spsite $url
$web = $site.RootWeb
$pageUrl= "Social/Sites.aspx"
$webPartManager =  $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);
$webPart = $webPartManager.WebParts | where-object { $_.WebBrowsableObject.GetType().Name -eq "ProjectSearchBrowseWebpart" }

if($webPart -ne $null)
{
    $webPartManager.DeleteWebPart($webPart)
}
$web.Update();


In the script, I found the name of the Web Part "ProjectSearchBrowseWebpart", and the page to find it.
Then, I decided to compare the code of both pages “Social/Sites.aspx” from my mySite and from the user’s mySite, using SharePoint Designer 2013.


I found then the difference at the end of the code:

Hereunder is the code from my mySite, and in yellow, the missing code in the user’s mySite code:

            <div class="ms-contentFollowing-sitesRightZone ms-tableCell ms-verticalAlignTop">
                <div class="ms-contentFollowing-bottomZoneContainer">
                    <WebPartPages:WebPartZone runat="server" FrameType="None" ID="RightZone" Title="<%$Resources:sps,LayoutPageZone_RightZone%>" Orientation="Vertical"><ZoneTemplate>
                                                                           <SPSWC:ProjectSearchBrowseWebpart runat="server" CategoryString="Site" AllowEdit="False" ChromeType="TitleOnly" Description="The recommendations web part suggests content a user may wish to follow within a farm." Title="Suggested sites to follow" ID="projectSearchBrowseWebPart" __MarkupType="vsattributemarkup" __WebPartId="{344EF58F-509A-3DE1-T3DG-ID0T674FOR6Z}" WebPart="true" __designer:IsClosed="false" partorder="2"></SPSWC:ProjectSearchBrowseWebpart>

                                                                           </ZoneTemplate></WebPartPages:WebPartZone>
                </div>
            </div>
        </div>
    </div>
</asp:Content>


So, I simply made a copy/paste of the missing line, save the user’s “Social/Sites.aspx” page, and made a refresh of his mySite in the browser.

 ==>Problem solved.





Voilà,


That’s all Folks !!!