Current Navigation Query String Repeating Issue in SharePoint 2013

There is an issue in SharePoint 2013 site in the version before SP1 that if you enter a URL with query string it keeps on adding the query string multiple times whenever any user clicks on the URL or try to save it.

It can be fixed in two ways.

  1. Manual fixing
  2. PowerShell

Manual Fixing:

Follow the following steps for each navigation entry

  1. Remove the entry for navigation that has query string.
  2. Save the navigation.
  3. Now, add the entry again with query string and save it.
  4. Then edit the entry for navigation and remove the query string part and save it again.
  5. It would be reflected in the current navigation with query string and no changes appended.

Using PowerShell:

Following is the code snippet that would fix the current Navigation.

$site = get-SPSite <SITE_URL>
$web = $site.RootWeb
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$nav = $pubWeb.Navigation
$currentNav = $nav.CurrentNavigationNodes
$nonEmptyQueryStringNodes = $navNodes|?{$_.Properties["UrlQueryString"] -ne "" }
for($counter=0; $counter -lt $nonEmptyQueryStringNodes.Count; $counter++)
 $nonEmptyQueryStringNode = $nonEmptyQueryStringNodes[$counter]
 echo "Modifying $($nonEmptyQueryStringNode.Title) `n`n" 

 #modify the Url and its properties
 $nonEmptyQueryStringNode.Url = $nonEmptyQueryStringNode.Url.Substring(0, $nonEmptyQueryStringNode.Url.IndexOf("?"))
 $oldQueryString = $nonEmptyQueryStringNode.Properties["UrlQueryString"]
 $nonEmptyQueryStringNode.Properties["UrlQueryString"] = $oldQueryString.Substring($oldQueryString.LastIndexOf("?")+1)
 echo "Old Query String : " $oldQueryString "`n"
 echo "New Query String : " $nonEmptyQueryStringNode.Properties["UrlQueryString"] "`n"

You can run the above script by modifying the <SITE_URL> or you can use this script. It would fix all the current navigation with query strings. Hope this helps someone!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s