Sunday, December 19, 2010

Getting Data from Subsites to TopSite with Null Checking.



using System;
using System.Web.UI;

using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;
using Microsoft.SharePoint;
using System.Data;
namespace TestSampleCode001.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
string Title = string.Empty;
string Status = string.Empty;
string AssignedTo = string.Empty;
string WebTitle = string.Empty;
var query = from SPWeb subWeb in
SPContext.Current.Web.GetSubwebsForCurrentUser()
from SPListItem item in
subWeb.Lists["Tasks"].Items
orderby item["ID"] descending
select new
{

Title=item["Title"].ToString(),
Status=(item["Status"]==null) ? "Data
UnAvailable" : item["Status"].ToString(),
Priority = (item["Priority"] == null)
? "Data UnAvailable" : item["Status"].ToString(),
AssignedTo = (item["AssignedTo"] ==
null) ? "Data UnAvailable" :
item["AssignedTo"].ToString().Substring(item["AssignedTo"].ToString().
LastIndexOf("\\") + 1),
WebTitle=subWeb.Title
};

if (query.Count() > 0)
{
sgvTest.DataSource = query;
sgvTest.DataBind();
}

}
catch (Exception ex)
{

this.Controls.Add(new LiteralControl(ex.ToString()));

}

}

}

}

No comments:

Post a Comment