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.

  • Microsoft.SharePoint.Search.dll is obsolete? – RJ Cuthbertson Jan 30 '13 at 16:58
  • 1
    Part of deprecating Sandboxed webparts. – Francisco Aquino Jan 30 '13 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 – 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
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, privacy policy and cookie policy

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