Tuesday, July 15, 2014

Get DataTable from the list and Get SPListItem based on caml query

Get DataTable from the list
public static System.Data.DataTable GetListData(string strListName, string strViewFields, string strQuery)
        {
            try
            {
                SPWeb oWeb = SPContext.Current.Web;
                SPListItemCollection items = null;
                string strListURL = oWeb.Url + "/Lists/" + strListName;
                SPList oList = oWeb.GetList(strListURL);
                SPQuery oQuery = new SPQuery();
                oQuery.ViewFields = strViewFields;
                oQuery.Query = strQuery;
                items = oList.GetItems(oQuery);
                if (items.Count > 0)
                    return items.GetDataTable();
                else
                    return null;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

Get SPListItem from the list
public static SPListItem GetListItem(string strListName, string strViewFields, string strQuery)
        {
            try
            {
                SPWeb oWeb = SPContext.Current.Web;
                SPListItemCollection items = null;
                string strListURL = oWeb.Url + "/Lists/" + strListName;
                SPList oList = oWeb.GetList(strListURL);
                SPQuery oQuery = new SPQuery();
                oQuery.ViewFields = strViewFields;
                oQuery.Query = strQuery;
                oQuery.RowLimit = 1;
                items = oList.GetItems(oQuery);
                if (items.Count > 0)
                    return items[0];
                else
                    return null;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

No comments:

Post a Comment

Image noise comparison methods

 1. using reference image technique     - peak_signal_noise_ratio (PSNR)     - SSI 2. non-reference image technique     - BRISQUE python pac...