SharePoint 2016 – Change SuitBar’s Text, add a logo and URL – PowerShell

This is how you can change the OOTB ‘SharePoint’ text on the top left corner, and also add your logo and URL:

Add-PsSnapin Microsoft.SharePoint.PowerShell
$webapp = Get-SPWebApplication ""
$webapp.SuiteNavBrandingText = "Home Page"
$webapp.SuiteNavBrandingLogoTitle = "Home Page"
$webapp.SuiteNavBrandingLogoUrl = ""
$webapp.SuiteNavBrandingLogoNavigationUrl =""


Posted in SharePoint 2016 | Leave a comment

Rich Text Box (InputFormTextBox) not working within UpdatePanel in SharePoint 2016

After we have migrated some web parts from SharePoin 2010 to 2016. The rich text box (InputFormTextBox) is not working properly inside UpdatePanels.


After each Ajax call or partial page update:

1. An extra rich text box appears on the page;

2. The contents in the rich text box disappear.


1. Make sure the control that triggers the Ajax call and the rich text box are all inside the same UpdatePanel;

<asp:UpdatePanel ID=”UpdatePanelAll” UpdateMode=”Conditional” runat=”server”>

/************** The control and the Rich Text Box are inside the Updatepanel ****************/


2. Add the following JavaScript code on top of your page:

function EndRequestHandler() {
var richtextContolId = ”;
if (browseris.ie5up && browseris.win32 && !IsAccessibilityFeatureEnabled()) {


Posted in SharePoint 2016 | Leave a comment

Add an assembly into .wsp package

I have a project that needs to use Microsoft Exchange WebServices (Microsoft.Exchange.WebServices.dll). After I deployed the solution into SharePoint 2016, sometimes I receive the following error:

System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.Exchange.WebServices, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

Re-deploying the solution may or may not be able to fix it.

So I opened the project in Visual Studio and double click the “Package.package”, and then go to the “Advanced” tab, and click “Add”:


Add the following info and then click “OK”:


If you go to the Manifest tab, you can see the assembly as been added:


Re-deploy the solution.

Posted in SharePoint 2010, Visual Studio 2010, Web Service, SharePoint 2016 | Leave a comment

System.Net.WebRequest throws a “(401) Unauthorized” error: The Double Hop Syndrome.

When using System.Net.WebRequest to POST (or GET) data to a SharePoint page, a 401 Unauthorized error occurs.
For example:
Uri address = new Uri(“;);
System.Net.WebRequest request = System.Net.WebRequest.Create(address);
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Method = “GET”;
System.Net.WebResponse response = request.GetResponse(); 
The error occurs on the request.GetResponse();

This works fine on your development enviroment (only if everything is on the same server), but as soon as you go live on production where IIS and SQL Server are located in two differnet machines , you will get : The remote server returned an error: (401) Unauthorized

The reason is ASP.NET code accesses DefaultCredentials to use in WebRequest. DefaultCredentials are based on impersonation token,but DefaultCredentials contains an impersonated token and not the primary one, so it cannot hop to SharePoint Content Database (where the document and document library is stored) to create the web request.



Replace this line:

request.Credentials = System.Net.CredentialCache.DefaultCredentials;

With this:

request.Credentials = new System.Net.NetworkCredential(“aUserName”, “thePassword”, “theDomain”);

i.e., We are re-creating the windows security context and providing the password.

Hope this helps someone.

P.S. if the target page has a Response.Redirect(“anotherpage.aspx”), it could also give you a 401 error.

Posted in SharePoint 2016, Visual Studio 2010 | Leave a comment

Get error messages by Correlation ID

When I get an error in SharePoint with a correlation ID, I find it easy to use the following PowerShell script to search for the detailed error message within the farm:

Add-PsSnapin Microsoft.SharePoint.PowerShell

Merge-SPLogFile -Path C:\Temp\log\log.txt -Level “Unexpected” -Correlation 6911329e-d6ff-c016-d2d4-1cd533dc1c03 -Overwrite

It will export the error message to this file C:\Temp\log\log.txt

Posted in SharePoint 2010, PowerShell, SharePoint 2016 | Leave a comment

Add SharePoint Web Services

  1. In Solution Explorer, right-click the name of the project that you want to add the service to, and then click Add Service Reference.

    The Add Service Reference dialog box appears.

  2. In the Add Service Reference dialog box, click the Advanced button.

    The Service Reference Settings dialog box appears.

  3. In the Service Reference Settings dialog box, click Add Web Reference.

    The Add Web Reference dialog box appears.

  4. In the URL box, enter the URL of the Web service to use. e.g.,
Posted in SharePoint 2010, Web Service, SharePoint 2016 | Leave a comment

Event Receiver does not fire

I wrote an event receiver for a list but it seems not firing when you add/update/delete an item.

I used the following Powershell script to see what event receivers that are attached to this list:

Add-PsSnapin Microsoft.SharePoint.PowerShell
$spWeb = Get-SPWeb -Identity http://yourWebUrl
$spList = $spWeb.Lists[“The List’s Name”]
$spList.EventReceivers | Select Name,Assembly,Type

Turned out there were some older event receivers that are still attached to it.

I then had to use the following script to delete all event receivers for this list:

Add-PsSnapin Microsoft.SharePoint.PowerShell
$spWeb = Get-SPWeb -Identity http://yourWebUrl
$spList = $spWeb.Lists[“The List’s Name”]
$numberOfEventReceivers = $spList.EventReceivers.Count
if ($numberOfEventReceivers -gt 0)
for( $index = $numberOfEventReceivers -1; $index -gt -1; $index–-)
$receiver = $spList.EventReceivers[$index] ;

After deleting the event receivers, deployed my receivers again and it worked like a charm!


Posted in PowerShell, SharePoint 2010 | Leave a comment