Common Methods


//GetListItemCollection
public SPListItemCollection GetListCollection(SPList lst, string queery)
        {
            //list = GetList(lst);
            if (lst != null)
            {
                SPQuery qry = new SPQuery();
                string stringQuery = queery;
                qry.Query = stringQuery;
                itemCollection = lst.GetItems(qry);
            }

            return itemCollection;
        }
//Insert An Item into a list
 public SPListItem InsertItem(SPList lst)
        {
         
            itemadd = lst.Items.Add();
            if (lst != null)
            {
                return itemadd;
            }
            else
            {
                return null;
            }

        }

//Reading Grid view Column valus
public String  GetGridviewColumnData(GridViewRow row, string columnName)
        {
            Label lblCol = row.FindControl(columnName) as Label;
         
            if (lblCol != null)
            {
                ct.colValue = lblCol.Text;
                return ct.colValue;
            }
            else
            {
                ct.colValue = string.Empty;
                return ct.colValue;
            }
        }


//GetUser values into a Collection
 public List<string> Getusercollection(SPList lst, string query)
        {
            itemCollection = GetListCollection(lst, query);
            List<string> strlist = new List<string>();
            foreach (SPListItem item in itemCollection)
            {
                strlist.Add(item["UserName"] != null ? item["UserName"].ToString() : string.Empty);
                string strVal = string.Join(",", strlist.ToArray());
            }
            List<string> result = (from m in strlist select m).Distinct().ToList();//it  is used to remove duplicates
            return result;
        }

//Get list
 public SPList GetList(SPList lst)
        {
            using (SPSite site = new SPSite(URL))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    if (lst != null)
                    {
                        return list;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
        }

Comments

Popular posts from this blog

Client Methods In Rest API

My Interview Experience