Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XML inquiry , hide not needed columns like ows_MetaInfo

Posted on 2014-04-07
4
Medium Priority
?
485 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 41

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 41

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

783 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