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

C# 使用C通过Web服务获取SharePoint列表可见列名称#,c#,web-services,sharepoint,sharepoint-2007,C#,Web Services,Sharepoint,Sharepoint 2007,我想获取sharePoint站点中特定列表的所有可见列(Hidden==false),我试图查看SharePointWebService.Lists.GetList(listName),但找不到任何有用的内容,还检查了Lists WebService提供的方法,也没有什么新内容 请注意。该方法返回一个包含列表字段(列)定义的CAML片段。您可能想尝试以下方法: 您可以使用listweb服务的方法来获取列表和视图的模式 从文档中,如果将viewName参数保留为空,将返回默认视图。然后,您可以读取

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

请注意。

该方法返回一个包含列表字段(列)定义的
CAML
片段。您可能想尝试以下方法:

您可以使用listweb服务的方法来获取列表和视图的模式

从文档中,如果将
viewName
参数保留为空,将返回默认视图。然后,您可以读取
节点中的字段列表

*编辑*

事实证明,使用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);
}
XmlNode result=webService.GetListAndView(“我的图片”,string.Empty);
XmlNamespaceManager nsmgr=新的XmlNamespaceManager(result.OwnerDocument.NameTable);
nsmgr.AddNamespace(“sp”http://schemas.microsoft.com/sharepoint/soap/");
字符串xpathQuery=“sp:View/sp:ViewFields/sp:FieldRef”;
XmlNodeList nodes=result.SelectNodes(xpathQuery,nsmgr);
for(int i=0;i

看起来您必须有一个
XmlNamespaceManager
,否则您的查询总是不返回任何值。有关指定命名空间的内容。。。以下是。

我使用了上述代码,但经过长时间搜索后,我找到了从sharepoint列表中获取所有或自定义列的解决方案。其代码在上共享


解决方案非常简单。使用
GetList()
或类似函数是错误的

相反,使用
getListContentTypesSync()
获取内容ID,然后使用
GetListContentTypeAsync()
获取特定的
ContentType
,它返回包含sharepoint列表中所有可见列的XML:

var Contents = await soapListClient.GetListContentTypesAsync(list.Title, "0x01"); // 0x01 is kind of a root element for sharepoint.
String ContentID = Contents.Body.GetListContentTypesResult.Descendants().FirstOrDefault().Attribute("ID").Value.ToString();
var ContentType = await soapListClient.GetListContentTypeAsync(list.Title, ContentID);
XElement xmll = XElement.Parse(ContentType.Body.GetListContentTypeResult.ToString());

我一直在研究'List'innerXml,我刚刚注意到没有属性Hidden=“TRUE”:S我将重新表述我的问题:当用户通过sharePoint网站打开列表时,我如何读取列表中显示的所有列?@Rami sharef:你是指在列表的默认视图中?@Kit:没错,sharePoint site.com中的默认视图似乎很有趣,我会尽快尝试并发布结果ViewFields返回字段的名称,因此我必须按名称重新调整每个字段以获得其显示名称,第二个问题是ViewFields没有显示该列表在sharePoint默认视图中显示的所有字段(如果列表是图片列表)!有什么想法吗?我尝试了这个方法来获取字段,System.Xml.XmlNode list=SPListWebService.GetListAndView(XmlNode.Attributes[“Title”].Value,string.Empty);System.Xml.XmlNodeList visibleColumns=list.SelectNodes(“View/ViewFields/FieldRef”);…我哪里弄错了?Rami,看起来你是对的。ViewFields节点包含所有FieldRef,它们是内部列名。当我尝试时,我得到:SelectedFlag、DocIcon、NameOrTitle、ImageSize、FileSizeDisplay和RequiredField。然后,你可以在响应的第一部分中查找关于这些字段的更多信息:ListAndView/List/Fields.Kit,这也没有给我任何信息!我迷路了,如何正确地读取响应孤独的链接是因为它本身毫无意义,目标资源也不能保证在将来仍然存在。请在此处包含答案的基本部分,并提供链接以供参考。
var Contents = await soapListClient.GetListContentTypesAsync(list.Title, "0x01"); // 0x01 is kind of a root element for sharepoint.
String ContentID = Contents.Body.GetListContentTypesResult.Descendants().FirstOrDefault().Attribute("ID").Value.ToString();
var ContentType = await soapListClient.GetListContentTypeAsync(list.Title, ContentID);
XElement xmll = XElement.Parse(ContentType.Body.GetListContentTypeResult.ToString());