Showing posts from April, 2010

How to Use CAML Query to get Data from SharePoint 2007 List

I was enjoying my summer with some CAML queries – All I wanted was to get some data from a simple Products List in SharePoint 2007. The list was pretty simple with 2 colomns "Product" and "Cost". I used U2U to create a pretty descent CAML query. I created a simple website in VS2008 to test it !!! It all worked fantastically!!!
Here is my Quick Dirty code –
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace WebApplication1
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
SPList mylist=new SPSite ("http://sharepointlogics").OpenWeb ().Lists ["Products"];
SPQuery query=new SPQuery ();
query.Query = "";
SPListItemCollection items=mylist.GetItems (query);

foreach (SPListItem proditem in items )
Response.Write(proditem["Title"].ToString ());