Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have some data in sharepoint lists,I want to read particular data from the list and show them in my asp.net website,what should i do ?
Posted

Step 1:-Add a web reference of the list that you want to access the lists are exposed through services that reside in _vt_bin folder.

step 2:-Create object of Webreference_name.Lists obj=new Webreference_name.Lists()
obj.Credentials = System.Net.CredentialCache.DefaultCredentials;

step 3:- string listName = "list_name";
string viewName = "";
string rowLimit = "150";
XmlElement query = xmlDoc.CreateElement("Query");
XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");

step 4:-
SQL
query.InnerXml = "<Where><Gt><FieldRef Name=\"ID\" />" +
                    "<Value Type=\"Counter\">1</Value></Gt></Where>";


XML
StringBuilder fieldRef = new StringBuilder();
fieldRef.Append("<FieldRef Name=\"Field_Name\" />");


XML
viewFields.InnerXml = fieldRef.ToString();



               queryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>";


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




XmlDataDocument xmlDocResult = new XmlDataDocument();
xmlDocResult.LoadXml(nodeListItems.InnerXml);
XmlNodeList rows = xmlDocResult.GetElementsByTagName("z:row"); //fetching data from xmlnodelist on row basis
foreach(XmlNode attr in rows)
{
//logic
}
 
Share this answer
 
v7
Comments
Member 10481338 5-Feb-14 1:50am    
Thank you , but the last part of your code : XmlDataDoc...
I have a warning : ( 'System.Xml.XmlDataDocument' is obsolate : 'XmlDataDocument class will be removed in future release' ) and how can I read data inside the list and show that as a text?
and my nodeListItems.Value is null, is it ok !?
SwarupDChavan 6-Feb-14 6:11am    
Regarding the warning I think it comes up for .net 4 and further version,for that you can have a go for the linq to xml that should help you or give a try by using XmlDocument class instead of XmlDataDocument.

For null values have a quickwatch for the values of the nodeListItems check whether it has value if it is not null then you can access the values in the foreach loop that I have specified in the code.
Member 10481338 23-Feb-14 3:13am    
Thank you, but I use this link : http://msdn.microsoft.com/en-us/library/hh134614(v=office.14).aspx , I think this is better.
 
Share this answer
 
I found this one as the Easiest approach. NOTE: it requires Microsoft.sharepoint.dll to be added in your project reference

using (SPSite site = new SPSite("http://abc.com/project/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Country"];
ddlCountry.DataSource = list.Items;
ddlCountry.DataValueField = "Title";
ddlCountry.DataTextField = "Title";
ddlCountry.DataBind();
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900