Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
Microsoft.SharePoint.Search.dll is obsolete? –  RJ Cuthbertson Jan 30 '13 at 16:58
1  
Part of deprecating Sandboxed webparts. –  F.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

1 Answer 1

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

 
discard

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.