0

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); 

clientContext.ExecuteQuery();

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.

4
  • Microsoft.SharePoint.Search.dll is obsolete? Commented Jan 30, 2013 at 16:58
  • 1
    Part of deprecating Sandboxed webparts. Commented Jan 30, 2013 at 17:29
  • Go to msdn.microsoft.com/en-us/library/… Many classes are obsolete. I am using Sharepoint 2013 standard and Visual Studio 2012 Commented Jan 30, 2013 at 17:45
  • Do you issue a search query from the server? Then you should use Microsoft.SharePoint.Server.Search.dll
    – oldbam
    Commented Feb 8, 2013 at 10:19

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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