Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE.eu :: How to Retrieve Lists from SharePoint using Webservice?
Today, I will tell you about how to Retrieve Lists from SharePoint using Webservice. This following code will give you all the list from SharePoint with the details of particular list. You can change BaseType to get different types of list from SharePoint.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Xml; using System.Xml.Linq; using System.Windows.Forms; using System.Resources; using System.Web; //To add below namespace you should add below reference library. //1.)Microsoft.SharePoint.Client.dll //2.)Microsoft.SharePoint.Client.Runtime.dll using Microsoft.SharePoint; //add this namespace to access SharePoint Web Service. using Microsoft.SharePoint.Client; //add this namespace to access SharePoint Web Service. using Microsoft.SharePoint.Utilities; //add this namespace to access SharePoint Web Service. namespace WindowsFormsApplication1 { public partial class COM : System.Windows.Forms.Form { string url = string.Empty; string listName = string.Empty; string listGUid = string.Empty; string rowLimit = ""; System.Net.NetworkCredential creadential = new System.Net.NetworkCredential("username", "password", "domain"); public COM() { InitializeComponent(); } private void btngetlist_Click(object sender, EventArgs e) { string listname = string.Empty; if (txturl.Text == string.Empty) { MessageBox.Show("Please Insert Valid Site URL!", "URL Needed!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { url = txturl.Text; List<string> lst = getlist(url); } } public List<string> getlist(string url) { string listname = string.Empty; ListWebService.Lists lst = new ListWebService.Lists(); List<string> listnames = new List<string>(); lst.Url = url + "/_vti_bin/Lists.asmx"; lst.Credentials = creadential; try { XmlNode xnode = lst.GetListCollection(); XmlNodeList node = xnode.SelectNodes("*[@BaseType=1]"); //change BaseType to retrieve Different list. foreach (XmlNode list in node) { //if(Convert.ToInt32(list.Attributes["BaseType"]) == 0) listname = list.Attributes["Title"].Value.ToString(); combolist.Items.Add(listname); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return listnames; } public void combolist_SelectedIndexChanged(object sender, EventArgs e) { ListWebService.Lists lst = new ListWebService.Lists(); url = txturl.Text; lst.Credentials = creadential; try { listName = combolist.SelectedItem.ToString(); XmlNode xnode = lst.GetListCollection(); XmlNode list = lst.GetList(listName); XmlNodeList visibleColumns= list.SelectNodes("Fields/Field[not(@Hidden) or @Hidden='FALSE']"); System.Xml.XmlNode nodlistview = lst.GetListAndView(listName, string.Empty); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(nodlistview.OuterXml); XmlNodeList xmllist = xmldoc.GetElementsByTagName("ViewFields"); xmldoc = new System.Xml.XmlDocument(); System.Xml.XmlElement query = xmldoc.CreateElement("Query"); System.Xml.XmlElement viewfield = xmldoc.CreateElement("ViewFields"); xnode = xmllist.Item(0); string queryinnerxml = string.Empty; for (int i = 0; i < xnode.ChildNodes.Count; i++) { if (xnode.ChildNodes[i].Attributes["Name"].Value != "Edit") { queryinnerxml = queryinnerxml + "<FieldRef Name=\"" + xnode.ChildNodes[i].Attributes["Name"].Value + "\" />"; } } viewfield.InnerXml = queryinnerxml.Trim(); System.Xml.XmlElement queryoption = xmldoc.CreateElement("QueryOptions"); queryoption.InnerXml = "<IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>"; System.Xml.XmlNode nodelistitem = lst.GetListItems(listName, string.Empty, query, viewfield, rowLimit, queryoption, null); System.IO.StringReader xmlsr = new System.IO.StringReader(nodelistitem.InnerXml); DataSet ds = new DataSet(); ds.ReadXml(xmlsr); listgrid.DataSource = ds.Tables[1]; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } |
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options.
Print article | This entry was posted by Peter on February 13, 2020 at 7:48 am, and is filed under European SharePoint Server 2013 Hosting. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |