An unhandled exception of type Microsoft.SharePoint.Client.ServerException ocurred in Microsoft.SharePoint.Client.Runtime.dll Cannot complete this action

This SharePoint csom tutorial, we will discuss how to fix an error An unhandled exception of type Microsoft.SharePoint.Client.ServerException occurred in Microsoft.SharePoint.Client.Runtime.dll Cannot complete this action in SharePoint Online/2013/2016.

Recently while working in a web api project for SharePoint online, I found the below error while trying to check if the document is exists using the document name using CAML query with csom (.Net Managed code). The error comes as:

ServerException was unhandled.
An unhandled exception of type Microsoft.SharePoint.Client.ServerException occurred in Microsoft.SharePoint.Client.Runtime.dll
Additional information: Cannot complete this action

An unhandled exception of type Microsoft.SharePoint.Client.ServerException ocurred in Microsoft.SharePoint.Client.Runtime.dll

An unhandled exception of type Microsoft.SharePoint.Client.ServerException occurred

Below CAML code I was writing in CSOM.

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "< View >< Query >< Where >< Eq >< FieldRef Name = ‘FileLeafRef’ />< Value Type = ‘File’ > "+ docLinkName + " </ Value ></ Eq ></ Where ></ Query ></ View > ";
ListItemCollection collListItem = lst.GetItems(camlQuery);

Here <View> was creating the issue. So I modified the code like below and it works fine.

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "< Query >< Where >< Eq >< FieldRef Name = 'FileLeafRef' />< Value Type = 'File' > "+ docLinkName + " </ Value ></ Eq ></ Where ></ Query >";
ListItemCollection collListItem = lst.GetItems(camlQuery);

You may like following SharePoint CAML tutorials:

This SharePoint tutorial helps us to learn how to solve an error An unhandled exception of type Microsoft.SharePoint.Client.ServerException occurred in Microsoft.SharePoint.Client.Runtime.dll Cannot complete this action which comes while working with SharePoint CSOM.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>