Access to a List

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hello all,

I would like to list all items in a list. I have tested every method
and already no result.

SPWeb site = SPControl.GetContextWeb(Context);
SPList list = site.Lists["KM"];
SPQuery query = new SPQuery();
query.Query = "<Query><OrderBy><FieldRef Name='Title'
/></OrderBy></Query>";
SPListItemCollection listItems = list.GetItems(query);
foreach (SPListItem listItem in listItems)
{
//this.Label1.Text +=
SPEncode.HtmlEncode(listItem["ows_Title"].ToString());
}



With this code I have a NullException here :

SPList list = site.Lists["KM"];

but my list called KM exists. I don't understand. :|

When I use this code :

sharepoint.SiteData srvSiteData = new sharepoint.SiteData();
srvSiteData.Credentials =
System.Net.CredentialCache.DefaultCredentials;
string items =
srvSiteData.GetListItems("{B17796BC-0493-4B50-A268-391CE4BD821D}",
"<Where><Eq><FieldRef Name=\"Title\" /><Value
Type=\"Text\">Test</Value></Eq></Where>", "<FieldRef Name=\"Title\"
/><FieldRef Name=\"Client\" />", 500);
this.Label1.Text += items;



I have no result.

I hope that you could help me.

.



Relevant Pages

  • trouble reading from sharepoint list
    ... I searched in the SharePoint Portal Team Services SDK and found the ... It is suppose to display all the contents of a list ... SPQuery query = new SPQuery; ... SPListItemCollection listItems = list.GetItems; ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: Programming surveys
    ... I blame it on lack of caffiene;) ... SPQuery query = new SPQuery; ... SPListItemCollection listItems = list.GetItems; ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: traversing through a sharepoint list
    ... SPQuery query = new SPQuery; ... SPListItemCollection listItems = list.GetItems; ... SPS MVP ... >i would like to kno how to traverse through a sharepoint list...i already ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: field value in sharepoint list
    ... SPSite siteCollection = SPControl.GetContextSite; ... SPQuery query = new SPQuery; ... SPListItemCollection listItems = list.GetItems; ... foreach ...
    (microsoft.public.sharepoint.portalserver.development)