SharePoint has many services and list.asmx is one service which lets you deals with its list and document libraries. In following example we will see how to call GetListItems method in list.asmx service
Lets start by creating a Console application in VS 2010. We will name this project as ConsoleApplication1
Next thing we will add is the reference to service list.asmx
Above service reference will also add a app.config file. We need to edit some its setting for our NTLM SharePoint site.
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
After changes we should have something like following
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
<!--<message clientCredentialType="UserName" algorithmSuite="Default" />-->
</security>
Above changes will help you get past following error
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.
Now we will write implement our service call. We will query list with name TestList. GetListItems method will return all the items under request list in XML format.
static void Main(string[] args) |
Following will be the output of above code
Hi i am getting an exception please help..
ReplyDeleteException of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
Hi Varun,
ReplyDeleteFirst thing you can make sure is that you run the code as service account or farm admin account. Next make sure the listname you are passing exists in the root site and not in any sub site.
Do you see more details in ex.Detail.InnerText?
Hi Ojas Thanks for the reply.
ReplyDeletei have added this line
listService.Url = "http://something/something/_vti_bin/lists.asmx";
to the code before calling
var ndListItems = listService.GetListItems("Posts", null, null, viewFileds, null, null, null);
and now no error i can retrieve the columns.
but what this line has does i dont know. i dont want to hard code the url.
one difficulty now i am facing is that one of the column is multi line and while retieving that the text comes with HTML..but i only want the content..If i am able to make u understand my problem?
Hi Varun,
ReplyDeleteDoes your multiline column support rich text. If yes then you will get HTML while reading it. If your multiline column was created as Plain text then you will get plain text.