We encountered another problem some days ago where we wanted to add promoted sites to our User Profile Service application -> My Site Settings -> Manage Promoted Sites using PowerShell.
Before proceeding, we should understand what promoted sites are.
For promoting some of the sites to all or a specific user group, we can use Promoted sites.
The following procedure shows how to add promoted sites to Central Administration manually.
- Go to "User Profile Service application" –> "My Site Settings" –> "Manage Promoted Sites" under Central Administration.
- Now select "New Link" and fill in the required details for the Promoted Site as shown in the following screenshot.
- Save the Promoted link and go to "Sites" navigation added on Top-Right in the SharePoint page. You will be able to see the newly added promoted site as shown in the following screenshot.
- You can also add the promoted site using the "Manage" link available, as shown in the following image.
Let's see how to add a Promoted Sites link using server-side C# code.
- SPSite siteColl = new SPSite("http://abc.com/");
- using(SPSite ElevatedsiteColl = new SPSite(siteColl.ID))
- {
- SPUser newUser = ElevatedsiteColl.RootWeb.EnsureUser(@
- "mydomain\user");
- SPServiceContext serviceContext = SPServiceContext.GetContext(ElevatedsiteColl);
- PromotedSitesViewWorker.AddSiteLink("http://abc.com/test1", "test1", "test desc1", string.Empty);
- }
You need to add references and the following using statements.
- using System.Reflection;
- using Microsoft.SharePoint.Portal;
- using Microsoft.SharePoint.Publishing;
- using Microsoft.SharePoint.Portal.UserProfiles;
The following PowerShell Snippet will add promoted sites.
- Add - PSSnapin "Microsoft.SharePoint.PowerShell" - ErrorAction SilentlyContinue;
- $site = Get - SPSite "http://abc.com/";
- $currentUser = [Environment]::UserDomainName + "\" + [Environment]::UserName;
- $serviceContext=Get-SPServiceContext $site
- $spuser=Get-SPUser -Web $site.RootWeb.Url -Identity $currentUser
- $imgUrl="
- ";
- [System.Reflection.Assembly]::Load("
- Microsoft.SharePoint.Portal, Version = 15.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c ");
- [Microsoft.SharePoint.Portal.UserProfiles.PromotedSitesViewWorker]::AddSiteLink($serviceContext,$spuser,"
- http: