In the sample below, I compared the title of the list to the “Title” attribute which is the generic display name. The “Name” attribute is the internal name of the list.
:: begin code sample ::
:: listName will be equal to the GUID of the list corresponding to the specified name ::
string listName;
XmlNode col = null;
XmlDocument doc = null;
XmlElement elem = null;
//setup the service
_service = new wsLists.Lists();
_service.Url = _siteUrl + "/_vti_bin/Lists.asmx";
//get the collection of lists from the service
col = _service.GetListCollection();
//load the collection into a document
doc = new XmlDocument();
doc.LoadXml(col.OuterXml.Trim());
//the document will have one child node that will contain all children
if ((doc.HasChildNodes) && (doc.ChildNodes.Item(0).HasChildNodes))
{
//look through the children to find the desired node
foreach (XmlNode node in doc.ChildNodes.Item(0).ChildNodes)
{
if (node.NodeType == XmlNodeType.Element)
{
elem = (XmlElement)node;
if (elem.GetAttribute("Title") == "My List Name")
{
listName = elem.GetAttribute("Name");
break;
}
}
}
}
:: end code sample ::
Future blog(s):
- Part 2 of this entry discussing how to get a collection of the items in the list.
1 comment:
Thanks for the great post! SharePoint Web Services are awesome!
Post a Comment