Encoded umlauts in file share search results.

If the SharePoint Search Crawler is indexing files on a file share that have german Umlauts (e.g. überprüfungsbedürftig.docx) than you will have problems with produced links, as they will have all of the umlauts encoded.

Encoding special characters in a links makes perfect sense, if you are dealing with a web link. The problem comes with indexing a file share, where the “links” are really only file path. Those paths when encoded make no sense and therefore produce an 404 error.

To fix this you can simply write some javascript code, that intercepts any clicked links that reference a file share and changes the encoded umlauts into their UTF-8 representation.

var linkClick=false;
document.onclick = function(e)
{
    linkClick = true;
    var elemntTagName = e.target.tagName;
    if(elemntTagName=='A' || elemntTagName=='STRONG')
    {
		var targetLink = null;

		if(elemntTagName=='A')
		{
           		var targetLink = e.target.getAttribute("href");
		}
		else if(elemntTagName=='STRONG')
		{
			var targetLink = e.target.parentElement.attributes.getNamedItem("href").value;
		}

		if(targetLink && targetLink.substr(0, 7) === "file://")
		{
			//%C3%BC - ü
			//%C3%9C - Ü
			//%C3%A4 - ä
			//%C3%84 - Ä
			//%C3%B6 - ö
			//%C3%96 - Ö
			var targetLink = targetLink.replace("%C3%BC", "ü").replace("%C3%9C", "Ü").replace("%C3%A4", "ä").replace("%C3%A4", "Ä").replace("%C3%B6", "ö").replace("%C3%96", "Ö");

			window.location.href = targetLink;
		}

        return false;
    }
}

Basic git svn commands guide

A quick guide to the simplest workflow for using git with an svn repository.

command function
git svn clone checkout
git svn rebase update
git svn dcommit commit
git reset HEAD file unstage file
git checkout filename reset file
git stash put all modified files "on the side" and go to HEAD

You can find a great and much more extensive guide here

And here you can find a few great tips and tricks from Atlassian.

Find SQL Server Alias

Quite often when I’m checking out a SharePoint Server I eventually want to get access to the SQL Server, that the SP Server is using for DB stuff. There is really no a lot of possibilites to do this. In SharePoin settings you will find references to the DB Servers alias (a friendly name), but not the actuall address or DNS resolvable name.

In order to find SharePoint Servers resolvable name you need to use the CLICONFIG tool.

You will usually find it here:
C:\Windows\System32\cliconfg.exe (64 bit version of cliconfig.exe)

After opening cliconfig and going to Alias tab, you will be able to identify your SQL Server name.

cliconfig

SharePoint Visual Web Part open links in the same window

The Visio Web Part in SharePoint is a great way to display your visio diagrams direstly in SharePoint.

It can also be used for other things, like displaying an interactive diagram with embedded links. This solution gives the user an ability to work with a diagram directly in Visio (no SharePoint knowledge required) and than simply upload the diagram to SharePoint, which displays it to some page for others to see.

This scenario is exactly what I was working on when I encounter a problem with the Visio Web Part.

The problem is that the Visio Web Part displays a clicked link in a context menu and always opens the link in a new window. This was not the behavior that the client wanted. Links should be opened in the same window and with now dropdows.

The solution turned out to be configuring the web part and some custom javascript.

Step 1: Configuring the Visio Web Part

Taken a simple Visio Diagram with test links

Test Visio Links

Test Visio Links

If you click on one of the links insted of directly transferring you to that link you will get a dropdown

Test Visio Links clicked

Test Visio Links clicked

Unfortunately the only fix for this behaviour is to disable of hyperlinks for the entire diagram.

This is possible in the Visio Web Part settings

Disable Hyperlink

Disable Hyperlink

Great, now we don’t have the context menu problem, but we can’t open any links. That is a bit crappy, I wil give you that. To fix this we need some javascript help.

Step 2: Custom javascript

Fortunatly for us we can implement opening links by ourselfes with javascript.

Include the below script in the page with your diagram with Script Editor Web Part for example and you are ready to go.

PowerShell: Transcript script output with newline

Recently I was searching for an easy way to log all output from my PowerShell script. This was a relatively low priority requirement so I’ve figured that if I won’t find an easy solution to this quickly, than I will drop it.

It turns out, that there is an easy way to do this. It’s called Transcript. It’s activated with Start-Transcript and deactivated with Stop-Transcript.

Transcript works only in the console, so if you are running your script in any IDE (Windows Powershell ISE for example), you will get an error. To avoid this, you can use code that looks like this:

if($host.name -eq 'ConsoleHost')
{
   Start-Transcript -Path "C:\Path\To\MyTranscript.txt" -Append
}

This will start the transcript feature only if the current script is executing in the console context.

To stop the transcript we can similarly use:

if($host.name -eq 'ConsoleHost')
{
    Stop-Transcript | Out-Null
}

The Stop-Transcript command normally produces a message. If you don’t want to see this message you can pipe the result to Out-Null.

There is another problem with this script. If you would look into the file that you are transcribing into, you would notice, that all of the output is in one “block”. This is because Transcript simply ignores empty Write-Host commands. This can be a problem if you want a human to read your transcript.

If your file is not too big, and you this is not a critical feature, you can use a hack to make it right:

if($host.name -eq 'ConsoleHost')
{
    Stop-Transcript | Out-Null

    $logContent = Get-Content $userRemoteLogDateiPath
    $logContent > $userRemoteLogDateiPath
}

Here we are reading the transcript, and writing the output once again into the file. This will produce our transcript with proper new lines.

This is a hack though and should only be used in simple situations with small files, because processing a big transcript like this could really affect your script performance.

Rebuild a mod_wsgi django project

If you are working on a project with the Django framework in wsgi mode, than after deployment of a change to production the project will not be automatically rebuilt.

I’ve lost a few hours because of this. The reason was the daemon on my production server. It would rebuild the project at arbitrary, at least to me, moments, and keep me wandering what is going on.

The solution turned out to be very simple. You can let the deamon know that your project needs rebuilding by simply changing the wsgi file, or changing it’s modification date (in linux you can accomplish this with the touch method).

My restart script is as simple as
touch /my/django.wsgi.

Deploy-SPSolution: PowerShell cmdlet for SharePoint package deployment

If you have ever done a SharePoint server solution, than you know that the deployment model is a bit specific.

After building a server solution for SharePoint and compiling it, you get a packed cab file with a .wsp extension.

To deploy this file to the SharePoint farm you have to user PowerShell.

This can of course be automated by Visual Studio, but what if you want to deploy the package on a production server where Visual Studio is not present ?

To automatically deploy my solutions and activate it’s features I have built a PowerShell cmlet. You can find the source here: Deploy-SPSolution.ps1.

Remove duplicates on the standard SharePoint search results page

If you don’t know what the “Remove Duplicate Results” feature is, than you can find a great introduction in this great article How “Remove Duplicate Results” works in FAST Search for SharePoint by leonardocsouza.

Suppose now, that you need to set the Remove Duplicate Results setting to false, but you don’t have a Search Center configured on your SharePoint site.

In this case your search reasults are redirected to the standard results page osssearchresults.aspx. This page however cannot be edited. Do you have to set up a Search Center Site just to be able to turn this feature off?

The answer is, as it often happens, depends.

On one hand, a good rule of thumb is to never edit SharePoint core files (if you have an alternative). In this case though we can set the url to our osssearchresults.aspx file on the site collection level. This allows us to use our own version of osssearchresults while leaving the original intact for further use.

On the other hand, if you are trying to customize the search results page, maybe you could use a search center and avoid the risks comming from playing with SharePoint core files.

The osssearchresults.aspx file is on the SharePoint root path under layouts.

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\osssearchresults.aspx

Remove duplicates on the standard SharePoint search results page 1Create a copy

Remove duplicates on the standard SharePoint search results page 2Edit the custom osssearchresults.aspx and find this div

<div class="srch-sitesearchmaintop">
  <SearchWC:CoreResultsWebPart runat="server" ShowActionLinks=false ChromeType="None"/>
</div>

Set the RemoveDuplicates attribute to false

<div class="srch-sitesearchmaintop">
  <SearchWC:CoreResultsWebPart runat="server" ShowActionLinks=false ChromeType="None" RemoveDuplicates="false"/>
</div>

You can find the attributes documentation here

Now navigate to the Search Collection which search results page you want to customize and go into Search Settings

Remove duplicates on the standard SharePoint search results page 3You can change the path to your osssearchresults.aspx file in the filed under “Results page URL”

Remove duplicates on the standard SharePoint search results page 5Change it to the name of your custom page.

Remove duplicates on the standard SharePoint search results page 6Save and go back to your site. The Remove Duplicates feature should now be deactivated.

Hope this helps you guys.

Find the Id of a Ribbon button in SharePoint

When you are trying to customize the SharePoint Ribbon you might want to hide a few of the buttons. There are a few ways to do that, including obviously css manipulation. The recommended way is to deploy a custom action element with the following details.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="RemoveRibbonButton"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.XXX.YYY.ZZZ" />
      </CommandUIDefinitions>
    </CommandUIExtension>
  </CustomAction>
</Elements>

The text XXX.YYY.ZZZ symbolizes the name of the button on the ribbon. Most of the buttons have standard names, and can be guest, like the button for creating a new folder in a documents library – “Ribbon.Documents.New.NewFolder”. There are some buttons though, that are a bit different.

A good example is the button for editing with Infopath – “Ribbon.List.CustomizeList.Controls.btnCustomizeList2”. When looking for button names like this you may end up looking up the CMDUI.XML that is located in the SharePoint hive folder on the path: TEMPLATE\GLOBAL\XML. You can find a lot of the button names there, but unfortunately not all.

The solution to this problem is to look up the button id on the page. The id that we are looking for will be used there for the id of the link tag.

You could look up the button id in a few different ways, but probably the easiest would be to an elements inspector tool. Most modern browsers have this kind of tool automatically available in their developer tool suites.

With the inspector tool you can simply point to an element on the page, and see its properties. In the example below I am looking up the Infopath button.

Looking up the ribbon button id

Looking up the ribbon button id