Solved

XML inquiry , hide not needed columns like ows_MetaInfo

Posted on 2014-04-07
4
458 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 36
Image(7) 1 37
Hide Tab Page 3 20
Performance  Html.BeginForm vs jQuery 3 15
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now