SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
using (SPSite newSite = new SPSite(site.ID))
{
using (SPWeb newWeb = newSite.OpenWeb(web.ID))
{
foreach (SPGroup group in newWeb.Groups)
{
foreach (SPUser u in group.Users)
{
if (SPContext.Current.Web.CurrentUser.Name == u.Name)
{
SPQuery depquery = new SPQuery();
depquery.Query = "<Where><Contains><FieldRef Name='Title' /><Value Type='Text'>" + group.Name + "</Value></Contains></Where>";
SPListItemCollection item = SPContext.Current.Web.Lists[Constants.HNBDepartmentList()].GetItems(depquery);
if (item.Count > 0)
{
grpName = group.Name;
}
}
}
}
}
}
});
No comments:
Post a Comment