Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XML inquiry , hide not needed columns like ows_MetaInfo

Posted on 2014-04-07
4
Medium Priority
?
481 Views
Last Modified: 2014-04-11
Im trying to run a query on a sharepoint List and my goal here is to only return 4 columns Title, Region, Category and URL however im getting alot of columns that i dont need ows_MetaInfo, ows_PermMask etc. Any help would be appreciated
thanks

 SPPlaySiteLists1.Lists listService = new SPPlaySiteLists1.Lists();
            
            
            listService.Credentials =
                System.Net.CredentialCache.DefaultCredentials;

            /*Set the Url
                "http://mylist/_vti_bin/Lists.asmx";

            /* Instantiate an XmlDocument object */
            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

          
            string listName = "List Name";
            //string viewName = "{B9764C7C-9AF2-4062-9A8E-FA7F4299DD32}";
            //string rowLimit = "150";

      
            System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
            System.Xml.XmlElement viewFields =  xmlDoc.CreateElement("ViewFields");
            System.Xml.XmlElement queryOptions =   xmlDoc.CreateElement("QueryOptions");


            query.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" +
         "<DateInUtc>TRUE</DateInUtc>";

            viewFields.InnerXml = "<FieldRef Name='Title' />" + "<FieldRef Name='Region' />" + "<FieldRef Name='Category' />" + "<FieldRef Name='URL' />";
            queryOptions.InnerXml = "<IncludeMandatoryColumns>False</IncludeMandatoryColumns>";
            

            System.Xml.XmlNode nodeListItems =
                listService.GetListItems
                (listName, null, query, viewFields, null, queryOptions, null);

            /*Loop through each node in the XML response and display each item.*/

            System.IO.StringReader sr = new System.IO.StringReader(nodeListItems.OuterXml);
            XmlTextReader tr = new XmlTextReader(sr);
            DataSet ds = new DataSet("resultDataSet");
            ds.ReadXml(tr);
            if(ds != null && ds.Tables.Count >= 2)
            {
                this.dataGridView1.DataSource = ds.Tables[1];
            }

Open in new window

0
Comment
Question by:kentrg11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39984209
You can set the datasource to that and just have your grid bind to the columns that are needed.  It won't hurt anything and in fact makes the next person's life easier when they need to add another column.

Turn off your auto generate and add bound columns. Example here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx
0
 

Author Comment

by:kentrg11
ID: 39984297
Is there an easier route without binding?
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 1000 total points
ID: 39984453
I guess you could select it to a new datatable . . . but you're wasting a lot of resources because you're essentially looping over the entire table again, getting the columns you need, and pointing the datasource as the copied source.    VS just getting the copy source once and then displaying what you need to display.
var data = ds.Tables[1].AsEnumerable().Select
            (r => new
            {

                 //Column Name = r.Field<TYPE>("TableColumnName")
                  //eg:

                Title = r.Field<string>("Title"),
                Region = r.Field<string>("Region")
  //other columns

                      
                         }).ToList();
    this.dataGridView1.DataSource = data;

Open in new window

0
 
LVL 15

Assisted Solution

by:colly92002
colly92002 earned 1000 total points
ID: 39985748
You could create a XPathNavigator to select the nodes you want and and iterate over them, choosing each field you want?

Eg something like this:

// Create navigator   
XPathNavigator navigator = ndListItems.CreateNavigator();
// Set up namespace manager for XPath   
XmlNamespaceManager ns = new XmlNamespaceManager(navigator.NameTable);
ns.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
ns.AddNamespace("z", "#RowSetSchema");
 XmlNodeList nodes = ndListItems.SelectNodes("//*[name()='z:row'] ", ns);

foreach (XmlNode node in nodes)
{
                    // Get the ID and put it in a datatable...
                    DataRow dr = _dt.NewRow();
                    string id = node.Attributes["ows_ID"].InnerText;
                    dr["ID"] = id;
                    /// Do whatever else you want to do....
}

Open in new window

0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question