【问题标题】:How to Get the Title of a SharePoint List?如何获取 SharePoint 列表的标题?
【发布时间】:2012-07-26 16:31:42
【问题描述】:
我正在尝试使用 Web 服务从 SharePoint 检索列表。我遇到了this blog post 中描述的问题,即 GetList 方法显然希望传递列表的标题而不是列表的名称(即使参数称为“listName”)。我有列表的名称,但我不知道如何获取列表的标题。在哪里可以找到?
我在 Office 365 中使用 SharePoint,我相信是 2010。
【问题讨论】:
标签:
sharepoint
sharepoint-2010
office365
【解决方案1】:
有点过头了,但试试这段代码。它只是一个示例代码,您可能希望将其塑造成您的逻辑。
string listName = "MyList";
Lists.Lists listSvc = new Lists.Lists();
listSvc.UseDefaultCredentials = true;
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(listSvc.GetListCollection().OuterXml);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable);
nsmgr.AddNamespace("A", "http://schemas.microsoft.com/sharepoint/soap/");
XmlNode requiredList = xDoc.SelectSingleNode("//A:List[contains(@DefaultViewUrl,'" + listName + "')]", nsmgr);
string listTitle = requiredList.Attributes["Title"].Value;
XmlNode list = listSvc.GetList(listTitle);