How to set the SharePoint 2010 Enterprise Search Service Application “Default Content Access Account” by using PowerShell

If you want to set the SharePoint 2010 Enterprise Search Service Application "Default Content Access Account" by using PowerShell you can use this script:

$searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
$c= New-Object Microsoft.Office.Server.Search.Administration.Content($searchapp)
$c.SetDefaultGatheringAccount($crawlUser, (ConvertTo-SecureString $crawlPwd -AsPlainText -force))

($crawlUser is – of cause – the login of the account and $crawlPwd is the password in plain text)

FileNotFoundException while developing an external SharePoint application

If you develop a SharePoint Application with Visual Studio 2010, e.g. a Console Aplication, you may get an FileNotFoundException.

For example in this code (program.cs):

namespace DemoConsoleApp
    class Program
        static void Main(string[] args)
           SPSite site = new SPSite("http://sharepoint.local");  //<<--- FileNotFoundException
           SPWeb web = site.RootWeb;
           //your code here


I’ve maked the line of code where you may receive the exception.

I solved the problem by setting the platform target in the project settings: Go to “project settings”, select “Build” tab, set “Platform target” setting to the architecture of your platform. I always use “x64” there. – After that the exception is gone.

Activate Claim Based Authentication afterwards with PowerShell

You can active Claim Based Authentication for a SharePoint Web App afterwards if you missed that at creation time.

Use this PowerShell script:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
[System.Reflection.Assembly]::LoadFile($Env:CommonProgramFiles+"Microsoft SharedWeb Server Extensions14ISAPIMicrosoft.SharePoint.dll") | out-null

$webapp = Get-SPWebApplication "http://<sharepoint server>/"
write-host "Current: " $webapp.UseClaimsAuthentication
$webapp.UseClaimsAuthentication = $true


write-host "    New: " $webapp.UseClaimsAuthentication

How To Activate SharePoint Ribbon Tab by JavaScript Code

In the last weeks I’ve extended the sample project that I’ve created for “Ribbon Customization”. You find the project source code on Codeplex:

The related articles on my blog are:

There are lots of excellent articles out there about SharePoint 2010 Ribbon customization.

Some articles that helped me:

Especially the first blog post in the above list leaves a question open: "Using client-side code to show ribbon items".

I had the same problem: How to activate a custom SharePoint Ribbon tab by JavaScript code?

After some reading in SharePoint standard JavaScript files I found the solution. I used some jQuery too:

1: $(document).ready(function  () {


2:     ExecuteOrDelayUntilScriptLoaded(salesappActiveRibbonTab, "sp.ribbon.js" );




4:     function  salesappActiveRibbonTab() {


5:         try  {


6:             _ribbonStartInit("MyApp.SharePoint.Ribbon.CustomTab" , false , null );


7:         } catch  (e) {


8:         };


9:     };


10: });

This allows me to activate my custom Ribbon tab with ID "MyApp.SharePoint.Ribbon.CustomTab" by JavaScript code. It works pretty fine!

Update 1

Meanwhile I created an test project for adding a custom ribbon tab while runtime. There I have had the problem, that the ribbon was created correctly BUT was not activated thru the code above. After some debugging of MS Ribbon JavaScript I created the following code:

var ribbontestintervall = null;


function RibbonTestActiveRibbonTab2() {     try {         window.clearInterval(ribbontestintervall);


        if (typeof (_ribbonStartInit) == "function")             _ribbonStartInit('RibbonTest.SharePoint.Ribbon.CustomTab', false, null);


        if (true && typeof (_ribbonReadyForInit) == 'function' && !_ribbonReadyForInit()) {             ribbontestintervall = window.setInterval("RibbonTestActiveRibbonTab2()", 1000);         }     } catch (e2) {     };

So the Browser retries the activation of the tab as long as it works.

Update 2 (2011/01/14)

See my new post and sample project on CodePlex :

Sample Visual Studio 2010 project for creating a custom SharePoint 2010 Ribbon tab on runtime (!)

Update 3 (2011/03/03)

Next part posted today. See the part list at the top of this blog post.