gpt4 book ai didi

c# - 使用 C# 通过 Web 服务获取 SharePoint 列表可见列名称

转载 作者:太空狗 更新时间:2023-10-29 23:03:42 24 4
gpt4 key购买 nike

我想获取 sharePoint 站点中特定列表的所有可见列(隐藏 == false),我试图查看 SharePointWebService.Lists.GetList(listName),但找不到任何有用的东西,还检查了 Lists WebService 提供的方法,也没有什么新东西,

请指教。

最佳答案

您可以使用 GetListAndView列表 Web 服务的方法,用于获取列表和 View 的架构。

根据文档,如果您离开 viewName参数为空,将返回默认 View 。然后,您可以阅读 <ViewFields></ViewFields>字段列表的节点。

*编辑*

事实证明,使用 XPath 查询返回的 XML 比我想象的要难......这是我想到的:

XmlNode result = webService.GetListAndView("My Pictures", string.Empty);

XmlNamespaceManager nsmgr = new XmlNamespaceManager(result.OwnerDocument.NameTable);
nsmgr.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");

string xpathQuery = "sp:View/sp:ViewFields/sp:FieldRef";
XmlNodeList nodes = result.SelectNodes(xpathQuery, nsmgr);

for (int i = 0; i < nodes.Count; i++)
{
Console.WriteLine(nodes[i].Attributes["Name"].Value);
}

看起来你必须有一个 XmlNamespaceManager否则您的查询始终不返回任何值。关于指定命名空间的一些事情......这是a good reference .

关于c# - 使用 C# 通过 Web 服务获取 SharePoint 列表可见列名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4245678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com