Monday, April 18, 2016

SharePoint 2013 CAML Query Errors

I got this error while running a CAML Query from a SharePoint 2013 Client application:
System.ArgumentException: Value does not fall within the expected range.
This was happening only in the Prod environment.

One thing that needs to be checked is that in Central Administration > Resource Throttling > List View Lookup Threshold is high enough for all lookup fields in your query:

Tuesday, March 17, 2015

SPWeb.ParserEnabled property

When set to TRUE:

  • when a document is added to a document library, the values of the fields in the list item for the document are added to the metadata properties of the document file. 
  • when you download and upload it again these properties are kept 

When set to FALSE:

  • all of the above is ignored - no custom metadata properties from the library is added to the document when added or uploaded. 
  • the issue comes if you are using sandbox solutions - nothing works anymore since none of the solution properties of the package are set and thus you cannot activate / upgrade any solution.

Tuesday, September 30, 2014

Powershell: Delete Taxonomy Term

Delete a Term in a TermStore using PowerShell:
function Delete-SPTerm($SiteUrl, $TermStoreName, $TermName) { Start-SPAssignment -Global try{ $site = Get-SPSite $SiteUrl $session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site) $termstore = $session.TermStores[$termStoreName] $terms= $termstore.GetTerms($termName, $false) if($terms.Count -gt 0){ $terms[0].Delete() $termstore.CommitAll() Write-Host 'Term deleted!' }else{ Write-Host 'Term not found!' } } finally { Stop-SPAssignment -Global } }

Use example:
Delete-GroupTerm -SiteUrl "" -TermStoreName "" -TermName ""

Friday, November 15, 2013

SharePoint 2010 State Machine Workflow error: "Failed to Start Workflow"

I've been working on a custom state machine workflow for a specific content type. I've associated the workflow to the content type like this:


This workflow has a custom initiation form, in which I'm passing some options to the workflow.

After doing the association to the content type I started getting the following error: "Failed to Start Workflow"

After doing a bit of debugging and head scratching I found that in the StartListWorkflow() method inside the initiation page in which the workflow association is retrieved from the workflowList.WorkflowAssociations list and it does not take into consideration the ContentType workflow associations.

private void StartListWorkflow()
 SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];
        this.Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData());
 SPUtility.Redirect(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);

So I replaced this line:

SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];

with this line:

SPWorkflowAssociation association = this.workflowList.ContentTypes[workflowListItem.ContentTypeId].WorkflowAssociations[new Guid(this.associationGuid)];

in which I'm getting looking for the association in the WorkflowAssociations of the list content type of the workflowListItem.

Thursday, October 10, 2013

SharePoint 2010 - Enable and configure unique Document IDs

There is a great article on how to Enable and configure unique Document IDs on

In short you need to:

  • Activate the Document ID site collection feature
  • Enable and configure the use of Document IDs in a site collection

But what it doesn't mention is that behind the scenes there are two time jobs that need to run to activate this feature: one to add the Document ID column and one to generate unique ids for the existing documents. But, these jobs are set to run once a day.

So if you need your unique Document IDs to be activate right away, you need to go to Central Administration and run these two timer jobs for your respective web application:

  • Document ID enable/disable job 
  • Document ID assignment job