SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the Microsoft.SharePoint.Client.Search dll (Client Object Model) in a webpart because Microsoft.SharePoint.Search is obsolete.

When using the ClientContext.ExecuteQuery() method we get an "401 Unauthorized access error". To solve this issue I have used this piece of code:

System.Net.NetworkCredential cr = new System.Net.NetworkCredential("user", "password");   
clientContext.Credentials = cr;
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery); 


The same code works in a console application with no credentials but in a WebPart I get the 401 Unauthorized access error and the webpart needs to execute the query with the current logged user (I am in a Domain).

Any ideas?

Thanks everyone.

share|improve this question
Microsoft.SharePoint.Search.dll is obsolete? – RJ Cuthbertson Jan 30 '13 at 16:58
Part of deprecating Sandboxed webparts. – Francisco Aquino Jan 30 '13 at 17:29
Go to… Many classes are obsolete. I am using Sharepoint 2013 standard and Visual Studio 2012 – Alvmad Jan 30 '13 at 17:45
Do you issue a search query from the server? Then you should use Microsoft.SharePoint.Server.Search.dll – oldbam Feb 8 '13 at 10:19
up vote 2 down vote accepted

The Managed Client Object Model will not work in a SharePoint context. It's for "client" applications. You could try the Silverlight Client Object Model or calling the Search web service in JavaScript.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.