Solved

XML inquiry , hide not needed columns like ows_MetaInfo

Posted on 2014-04-07
4
474 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 250 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 250 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

630 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