0

I'm creating a webpart that gives the user a feed of any annoucement list in the entire site collection, so they can aggregate data to a central portal.

I'm currently using the following, but can't find a best practice or solid pattern and want to know if it's wrong:

static public List<SPListMeta> AllSiteAnnouncementsLists()
{
    var returnList = new List<SPListMeta>();
    var collWebs = SPContext.Current.Web.Site.WebApplication.Sites[0].OpenWeb().GetSubwebsForCurrentUser();
    //GetSubWebs igonores root web, so this is a fill in
    if(SPContext.Current.Site.RootWeb.DoesUserHavePermissions(SPBasePermissions.Open))
    {
        var collSiteLists = SPContext.Current.Site.RootWeb.GetListsOfType(SPBaseType.GenericList);
        returnList.AddRange(from SPList oList in collSiteLists 
                                    where oList.DoesUserHavePermissions(SPBasePermissions.ViewListItems) 
                                    && oList.BaseTemplate == SPListTemplateType.Announcements 
                                    select new SPListMeta(oList));
    }
    foreach (SPWeb oWebsite in collWebs)
    {
        if (oWebsite.DoesUserHavePermissions(SPBasePermissions.Open))
        {
            using (oWebsite)
            {
                var collSiteLists = oWebsite.GetListsOfType(SPBaseType.GenericList);
                returnList.AddRange(from SPList oList in collSiteLists 
                                    where oList.DoesUserHavePermissions(SPBasePermissions.ViewListItems) 
                                    && oList.BaseTemplate == SPListTemplateType.Announcements 
                                    select new SPListMeta(oList));
            }
        }
    }
    return returnList;
}
  • Is there a reason you are finding the lists instead of the Content Types they usually contain? – Dave Wise Oct 23 '12 at 21:43
  • Content Query web part pointed at the Announcements content type would be my vote. – Eric Alexander Oct 23 '12 at 22:15
  • @PirateEric Content quiry doesn't work. We're presenting the results in a custom UI. – Wesley Oct 23 '12 at 22:54
  • @DaveWise Once I find the list, I need to get the ParentWeb Guid, and the List Guid to access the list directly in the future to provide the feed. – Wesley Oct 23 '12 at 22:55
  • You can roll your own ItemStyle for the content query web part to display the results how you'd like. – Eric Alexander Oct 23 '12 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.