Monthly Archive » October 2010

Accessing parent web list items carefully

I spent quite some time today fixing this problem of accessing a list item in parent web. What I had to do was to access a list item in a parent web, but strangely it kept returning no result, and I made sure the item did exist in the list.

Then I found out it’s due to permission issue. When accessing a parent web’s list items, you have to run your code under elevated privileges mode, otherwise if you debug it you will see that it crashes when trying to access them.

How to select distinct from SPQuery CAML

A handy way to select distinct records from SPListItemCollection set queried from CAML query. This is very useful when we want to select a number of unique records from a data table.

DataTable dtt = myWeb.Lists["LISTNAME"].GetItems(spQuery).GetDataTable();
DataView dtv = new DataView(dtt);
dtt = dtv.ToTable(true, "COLUMNNAME");