Wednesday, March 2, 2016

How to retrieving next 7 Days Due Date Tasks from SharePoint List

C# Coding:


DateTime strdate = (DateTime)DateTime.Today.AddDays(7);
            string strgetDate = strdate.Year + "-" + strdate.Month + "-" + strdate.Date.Day;

SPWeb currentWeb = SPContext.Current.Web;
            SPList lst = currentWeb.Lists["Projects"];
            SPQuery sQuery = new SPQuery();
            sQuery.Query = "<Where><Geq><FieldRef Name='DueDate' /><Value Type='DateTime'>"+strgetDate+"</Value></Geq></Where><OrderBy><FieldRef Name='DueDate' /></OrderBy>";
            SPListItemCollection myColl = lst.GetItems(sQuery);
            if (myColl.Count > 0)
            {
                grdBind.DataSource = myColl.GetDataTable();
                grdBind.DataBind();
            }

No comments:

Post a Comment