Ömer Çelik

Yazılımcının Günlüğü

object model listeyi datatable olarak göstermek

    using (SPSite site = new SPSite("http://www.omercelik.com.tr"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["kategoriler"];
                    ConvertList2Datatable(list);
                }
            }
 private static DataTable ConvertList2Datatable(SPList oList)
        {
       DataTable dt = new DataTable();

            try
            {
                dt = oList.Items.GetDataTable();
                foreach (DataColumn c in dt.Columns)
                    c.ColumnName = System.Xml.XmlConvert.DecodeName(c.ColumnName);
                return (dt);

            }
            catch
            {
                return (dt);
            }
      }

başka bir yöntem

     using (SPSite site = new SPSite("http://www.omercelik.com.tr"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Duyurular"];
                    SPQuery query = new SPQuery();
                    query.Query = "<Where><Eq><FieldRef Name='kategori' LookupId='TRUE'/><Value Type='Lookup'>2</Value></Eq></Where>";

                    query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"ID\" />";
                    query.ViewFieldsOnly = true;
                    DataTable listItemsTable = list.GetItems(query).GetDataTable();
  }
      }

Loading