How to change the options in search drop down with CSOM

searchNavigation1

You can change the options in the drop down manually by going to Site Settings > Search > Search Settings and add or remove a link.

searchNavigation2

If you want to change the options of the drop down in the search bar, you unfortunately have to configure these for each web and not just for the root site collection. So you probably don’t want to configure it manually.

As you can’t you SSOM in SharePoint online you have to use the CSOM. You can’t access the search navigation in a “normal” way, because there is no object in CSOM for it. But you can get the search Navigation by its id (Thanks for the idea, Mikael):


public static void AddSearchNavigationNode(Web web, string title, string url)
{
var nav = web.Navigation;
NavigationNode searchNavigation = nav.GetNodeById(1040);
NavigationNodeCollection searchNavigationNodeCollection = searchNavigation.Children;
NavigationNodeCreationInformation searchNavigationNode = new NavigationNodeCreationInformation();
searchNavigationNode.Title = title;
searchNavigationNode.Url = url;
searchNavigationNode.IsExternal = true;
searchNavigationNode.AsLastNode = true;
searchNavigationNodeCollection.Add(searchNavigationNode);
web.Context.Load(searchNavigationNodeCollection);
web.Context.ExecuteQuery();
}

Please note that all the default options (Everything, People, This site) are getting removed, when adding a custom option via code.

How so set web properties within a web template

If you create a new web, based on a custom web template, you can set web properties like this:

  1. In your Visual Studio solution containing the web template, create a new module or use an existing one
  2. Paste the PropertyBag section into your module
  3. Put your module into a feature, that gets activated within your web template

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="MeetingPage">
    […]
    </Module>
    <PropertyBag Url="" ParentType="Web" RootWebOnly="FALSE">
    <Property Name="WebTemplateName" Type="string" Value="Atia-Template"/>
    </PropertyBag>
    </Elements>

In this example the Key “WebTemplateName” with Value “Atia-Template” is added to the web properties.
To check this you can use PowerShell:

$web=Get-SPWeb *your url*
$web.AllProperties

How to start a SharePoint 2013 Workflow on all list items via PowerShell

Unfortunately you can not use the same commands to start a SharePoint 2013 Workflow that you use to start a SharePoint 2010 Workflow via PowerShell.
Here’s what you’ve got to do:


$web = Get-SPWeb -Identity "http://portal.atia.com"
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web)
$list = $web.Lists["My List"]
$items = $list.Items
$sub = $wfm.GetWorkflowSubscriptionService()

$wfis = $wfm.GetWorkflowInstanceService()
$subscriptions = $sub.EnumerateSubscriptionsByList($list.ID)
$subscription = $subscriptions | Where-Object {$_.Name -eq 'IdeaCreated'}

#Optional step to filter list items (This example only selects the document sets, not the files)
$items=$items | Where-Object {$_.Folder -ne $null}

foreach($item in $items)
{
$object = New-Object 'system.collections.generic.dictionary[string,object]'
$wfis.StartWorkflowOnListItem($subscription, $item.ID, $object)
}
$web.Dispose()

How to install Workflow Manager 2013

  1. Download Microsoft Web Platform installer from https://www.microsoft.com/web/downloads/platform.aspx
    WF1
  2. Open Web Platform Installer. Select “Workflow Manager 1.0 Refresh”, click ‘Add’ and then ‘Install’.
    WF2
  3. Go through the configuration wizard and choose “Configure Workflow Manager with Custom Settings”
    WF3
    Supply user details and passwords, and accept the default values. Check “Allow Workflow management over HTTP on this computer” option if your system is not configured for HTTPS.
    WF4
    WF5
    WF6
    WF7
    WF8
    WF9
    WF10
    WF11
    WF12
    When you’ve finished the configuration wizard, check in IIS if the Application Pool “WorkflowMgmtPool” and the Site “Workflow Management Site” are running.
    WF17
    WF13
  4. Use PowerShell to connect your SharePoint to the Workflow Manager
    Register-SPWorkflowService -SPSite “*Url of you WebApplication or SiteCollection*" -WorkflowHostUri "http://workflow.example.com:12291" -AllowOAuthHttp
    (If you don’t know your WorkflowHostUri, check Get-WFFarm in PowerShell)
  5. Install Workflow Manager Client from Web Platform Installer
  6. Install Workflow Manager Tools 1.0 for Visual Studio 2012 from Web Platform Installer
  7. Check if Workflow Manager is configured correctly
    • Check in Central Administration (/_admin/WorkflowServiceStatus.aspx)
      WF14
    • Check in SharePoint DesignerTry to create a new Workflow and chose “SharePoint 2015 Workflow” as Platform Type.

Troubleshooting

  1. If you still can’t see the option “SharePoint 2013 Workflow” in SharePoint Designer, check if the following two hidden features are activated on your site collection. If not, use the PowerShell to do so (with –Force Attribute).
    WF15
    Workflow Service Store ID=”2c63df2b-ceab-42c6-aeff-b3968162d4b1″
    Workflow Task ID =”57311b7a-9afd-4ff0-866e-9393ad6647b1″
    Enable-SPFeature -Identity *Feature ID* –Url *SiteCollection URL* -Force
  2. Check if the Workflow Service Application Proxy is connected to your Web Application
    WF16

Uninstall Workflow Manager

If you want to uninstall Workflow Manger check this post.

Search has encountered a problem that prevents results from being returned

I got the following error in search results:

Fehlermeldung1

When looking into the Log-Files I found the following:

07/02/2015 13:17:56.99                w3wp.exe (0x6B58)                                      0x35AC SharePoint Server Search          Query                                         dka5      High      SearchServiceApplicationProxy::Execute--Error occured: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Tried IMS endpoints for operation Execute: Cannot plan query for index system SP687d6eeb0241. Index fragment '0' has no available cells. Cell statuses: [Cell I.0.0 on node IndexComponent1: Cell status is set to 'not available' (cell out of sync or seeding)] (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: Microsoft.SharePoint.SPException: Tried IMS endpoints for operation Execute: Cannot plan query for index system SP687d6eeb0241. Index fragment '0' has no available cells. Cell statuses: [Cell I.0.0 on node IndexComponent1: Cell status is set to 'not available' (cell out of sync or seeding)]   ... 990a169d-5bdf-904e-2a6f-03276c7b13e1

Here is how to fix this issue:

1. Stop the SharePoint Timer Service (Server Manager > Tools > Services)

Fehlermeldung3

2. Clear the SharePoint configuration cache. Therefore navigate to \ProgramData\Microsoft\SharePoint\Config and find the folder that contains the file cache.ini.

Fehlermeldung2

Delete all files in that folder, except the cache.ini. Afterwards open cache.ino in notepad an replace the content with a simple 1. Save the file.

Fehlermeldung4

3. Restart the SharePoint Timer Service (Server Manager > Tools > Services)

4. Do an index reset in Central Administration (Manage Service Applications > Search Service Application > Crawling > Index Reset)

5. Do a full crawl (Manage Service Applications > Search Service Application > Crawling > Content Sources)

Afterwards your search results should work as expected.

Problems with anonymous access for External Lists using Publishing Feature

While setting up external lists on a SharePoint 2013 Site Collection for anonymous access we came across a problem. We started the configuration of the External Content Type as explained in many blogs (Thanks Prashanth) :

1. Create the External Content Type in SharePoint Designer
2. Give execute permissions to a specific user (i.e. Max Mustermann) for the External Content Type, the BDC Model and the External System via central administration.
bild1
4. Export the External Content Type from SharePoint Designer (There is an option to export the External Content Type from Central Administration as well, but it doesn’t export all the details. You have to use the export function of SharePoint Designer).bild2
5. Open the exported bdcm-File in text editor. The exported file includes <AccessControlEntry> elements that specify what rights an individual user or group has to the External Content Type. Adding users to the BCS permissions via Central Administration creates additional entries in the XML of the model.  Look for <AccessControlList>-Entries in the whole document and replace the entries that where created for Max Musterman with the following:

Before After
<AccessControlList>
[…]
<AccessControlEntry Principal="domain\max.mustermann">
<Right BdcRight="Execute" />
</AccessControlEntry>
</AccessControlList>
<AccessControlList>
[…]
<AccessControlEntry Principal="NT Authority\Anonymous Logon">
<Right BdcRight="Execute" />
</AccessControlEntry>
</AccessControlList>

bild3
6. Save the file and go back to central administration.
7. Delete the External Content Type and the connected bdcm model and external system from business data connectivity service.

bild4
8. Import the bdcm-File into Central Administration with Permissions.bild5

We noticed that this scenario worked on most of our SharePoint servers, but not on every server. It took me a while to find out what the difference between the server configurations was. At first I found out, that it doesn’t work on the servers, where the SharePoint Publishing Feature is enabled. But it didn’t help to just disable the feature. After some googling I found the solution (Thanks Russ). There is a hidden feature named ViewFormPagesLockDown, which, if enabled, prevents anonymous user from accessing certain areas of a site collection.

9. You can disable it via PowerShell.

$lockdown = get-spfeature viewformpageslockdown

disable-spfeature $lockdown -url https://sitecollection

bild6

After disabling the feature via PowerShell, anonymous users where able to access my external list.

And if the list still isn’t loading, check if the anonymous users have  permissions on the root site collection to see the rendering templates, or just change the redering-mode of the list to server-side rendering.

SharePoint Page Layout Error: Only Content controls are allowed directly in a content page that contains Content controls

Today I got the following error, when I wanted to open and edit a page based on a custom page layout: Only Content controls are allowed directly in a content page that contains Content controls.

I found a lot of blog entries about that topic, and thanks to this one I finally found the solution:

The cause of the problem is a improper case for the control tags the page layout. Some of the contorls in my page layout used a lower case “c” instead of an uppercase “C”. I just changed <asp:content> to <asp:Content> in the whole document and afterwards all the pages based on that layout worked again.

SharePoint 30 minute Timeout for forms

I noticed that when you open a form in SharePoint and start to fill it out, SharePoint will time out that form after 30 minutes.

If you are filling out a form with a lot of data, or if you have to stop working on a form for a few minutes, this is very annoying because after 30 minutes all the work will be gone and you have to start filling the form all over again.

Here’s the solution:

PS> $SPSite = Get-SPSite("https://portal.lab.intern")
PS> $webApp = $SPSite.WebApplication
PS> $webApp.FormDigestSettings

Enabled Expires Timeout UpgradedPersistedProperties
——- ——- ——- —————————
True False 0:30:00 {}

PS> $webApp.FormDigestSettings.Timeout = New-TimeSpan -Hours 8
PS> $webApp.Update()

CustomAction isn’t showing for a content type

I ran into this problem today. I created a CustomAction that should show up in the DisplayForm of all Items having a specific content type, but it didn’t.
[...]
Location="CommandUI.Ribbon.DisplayForm"
RegistrationId="0x0100f112dac493564f9e847fcc900037b604"
RegistrationType="ContentType"
[...]

Here’s the simple solution:

It’s causing problems when content types don’t have all capitals in the identifier, both for the definition and when using. So I changed the RegistrationId to the following:
[...]
Location="CommandUI.Ribbon.DisplayForm"
RegistrationId="0x0100F112DAC493564F9E847FCC900037B604"
RegistrationType="ContentType"
[...]