Friday, 5 January 2018

Upgrade SharePoint 2016 Content Database when psconfig fails during CU

Run the following command:
Get-SPContentDatabase | ?{$_.NeedsUpgrade -eq $true} | Upgrade-SPContentDatabase

Sunday, 3 December 2017

SharePoint 2016 Client Side Web Part System.InvalidOperationException: The System Account cannot perform this action.

If while adding Client Side Web Part using Add an App on SharePoint 2016 causes the following error:
System.InvalidOperationException: The System Account cannot perform this action.

Ensure you are not using the System Account. Many of us get lazy while creating a Dev machine to test latest patches and use one account for all. If we use best practices a lot of these issues can be avoided :)

Thursday, 26 October 2017

Upgrade failed because of Missing Feature 'CustomTiles' (Id: 15/'68642d38-a556-4384-888c-082844fbf224')

CustomTiles is a SharePoint Feature and needs to be enabled for the update to succeed.

Run the following on all web applications:
Enable-SPFeature -Identity CustomTiles -Url WebApplicationUrl -Force

Wednesday, 29 July 2015

Remove Views and allitems.aspx from SharePoint 2013 Search Results

A lot has changed when it comes to search in SharePoint. Before we predominantly used crawl rules to exclude allitems.aspx. A similar crawl rule on SharePoint 2013 may cause the pages in the pages library not to be crawled.

The best solution is to use a result source to refine the search results. 

  1.  Make a copy of the out of the box  "Local SharePoint Results" result source.
  2. Update the query text to remove unwanted results. Below will remove allitems.aspx, custom views on pages libraries and folders. You may also want to add other contenttypes to be excluded:
    • {?{searchTerms} -ContentClass=urn:content-class:SPSPeople -filename:allitems.aspx -contentclass:STS_List_850 -filename:dispform.aspx -ContentType:Folder}
  3. Edit the search results web part to use the newly created Result Source.
That should give you better search results.

Monday, 11 August 2014

How to Post to Newsfeed / Sitefeed Programmatically in SharePoint 2013

Today I was trying to create a simple console application to post to a SharePoint 2013 sitefeed using server object model. Surprisingly there was no good article out there.
If it helps anyone, following is how I did it :

Add references

Microsoft.Office.Server.UserProfiles.dll
Microsoft.Office.Server.dll
System.Web.dll

Using Directives

using Microsoft.SharePoint;
using Microsoft.Office.Server.Social;
using Microsoft.Office.Server.UserProfiles;

Code

static void Main(string[] args)
        {
            const string siteUrl = "http://server/sites/sitename";
            const string user = "domain\\username";

            using (SPSite site = new SPSite(siteUrl))
            {
                SPUser userContext = site.RootWeb.SiteUsers[user];
                SPUserToken userToken = userContext.UserToken;

                SPServiceContext serviceContext = SPServiceContext.GetContext(site);

                using (new SPServiceContextScope(serviceContext))
                {

                    UserProfileManager profileManager = new UserProfileManager(serviceContext);

                    UserProfile userProfile = profileManager.GetUserProfile(userContext.LoginName);

                    SPSocialFeedManager feedManager = new SPSocialFeedManager(userProfile, serviceContext, userToken);

                    SPSocialPostCreationData post = new SPSocialPostCreationData();
                    post.ContentText = "Hi from server object model";

                    feedManager.CreatePost(site.Url+"/newsfeed.aspx", post);

                }
            }
        }

Troubleshooting


If you come across UserProfileApplicationNotAvailableEx, the chances are it is a permission issue. Use this article to solve it: Get User profile using Console App- Object reference error at Server context

If you encounter “User cannot be found” exception at site.RootWeb.SiteUsers[userName], try “i:0#.w|domain\\username” instead of “domain\\username