Using Sharepoint List Webservice

No.of Views1142
Bookmarked0 times
Downloads 
Votes0
By  amalhashim   On  15 Feb 2010 23:02:11
Tag : SharePoint , Development and Programming
Using Sharepoint List Webservice
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Sharepoint exposes some really useful webservices. One among the most useful is the List Webservices.

We can take the webreference from the following location

http://mossserver/_vti_bin/lists.asmx

Once we have added the webservice, we can use following generic method to call webservice.

{codecitation class="brush: csharp; gutter: true;" width="700px"}

XmlNode CallWebService(bool isRecursive, ListsService listService,
string listName, string queryObj, string viewID, string viewFieldsInnerXml)
{
try
{
NetworkCredential credential = new NetworkCredential();
credential.UserName = "UserName";
credential.Password = "Password";
credential.Domain = "Domain";
listService.Credentials = credential;

// Instantiate an XmlDocument object
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

string viewName = string.Empty;
if (string.Empty != viewID)
{
viewName = viewID;
}
string rowLimit = "150";

System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");

if (isRecursive)
queryOptions.InnerXml = "";
else
queryOptions.InnerXml = "";

if (string.Empty == queryObj)
{
query.InnerXml = "" +
"0
";
}
else
{
query.InnerXml = queryObj;
}

// Assign View fields
if (string.Empty != viewFieldsInnerXml)
{
viewFields.InnerXml = viewFieldsInnerXml;
}
else
{
viewFields.InnerXml = "";
}
System.Xml.XmlNode nodeListItems =
listService.GetListItems(listName, viewName, query,
viewFields, rowLimit, queryOptions, null);

return nodeListItems;
}
catch (Exception ex)
{
throw ex;
}
}

{/codecitation}

You can use this generic method for getting the list items.
Pass true to “IsRecursive” if you want to get items inside folder.


Example:


{codecitation class="brush: csharp; gutter: true;" width="700px"}

string fields = "
";
XmlNode nodeListItems = CallWebService(true, l, "Answer Choices",
string.Empty, string.Empty, fields);

foreach (System.Xml.XmlNode listItem in nodeListItems)
{
if (listItem.ChildNodes.Count > 0)
{
foreach (XmlNode node in listItem.ChildNodes)
{
string choice = node.Attributes["ows_Title"]
.Value;
}
}
}

{/codecitation}

That's all, try in your development.

Thank you

Amal

 
Sign Up to vote for this article
 
About Author
 
amalhashim
Occupation-Software Engineer
Company-Aditi Technologies
Member Type-Senior
Location-Not Provided
Joined date-07 Jun 2009
Home Page-http://lamahashim.blogspot.com
Blog Page-http://lamahashim.blogspot.com
I have done my masters in Computer Applications and graduation in Computer Science. I have great passion in working with Microsoft tool and technologies. I am also a Microsoft Most Valuable Professional. Personally my objective is to design/develop applications which eases user experience and performs better in long run.
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top