Get visible column names of SharePoint using a web service using C #

I want to get all visible columns (Hidden == false) for a specific list on the sharePoint site, I tried to browse SharePointWebService.Lists.GetList(listName), but could not find anything useful, I also checked the methods provided by the WebService lists and also nothing new,

Please advice.

+5
source share
4 answers

You can use the GetListAndView method of the list web service to get the schemas for the list and view.

, viewName , . <ViewFields></ViewFields> node .

* *

, 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, . - , ... .

+5

GetList() CAML, (). XPath:

XmlNode list = yourListService.GetList("yourListName");
XmlNodeList visibleColumns
    = list.SelectNodes("Fields/Field[not(@Hidden) or @Hidden='FALSE']");
+1

, sharepoint. .

+1

. GetList() - .

GetListContentTypesAsync(), , ContentType GetListContentTypeAsync(), XML, sharepoint:

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());
0

All Articles