Expand Minimize

SPC050239: Do not call PublishingWeb.GetPublishingPages()

Do not call PublishingWeb.GetPublishingPages(). Use PublishingWeb.GetPublishingPages(SPQuery query) or PublishingWeb.GetPublishingPages(uint rowLimit) instead to improve performance and limit the number of returned pages. Note: PublishingWeb.GetPublishingPages() does not return pages inside subfolders. Use then PublishingWeb.GetPublishingPages(SPQuery query) instead.

CheckId SPC050239
TypeName DoNotUseGetPublishingPages
Severity CriticalWarning
Type Assembly

Use PublishingWeb.GetPublishingPages(SPQuery query) or other alternative methods instead.
Good Practice

// use the following code to include pages in subfolders
using (SPSite site = new SPSite("http://moss"))
{
    SPWeb web = site.RootWeb;
    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
    SPQuery query = new SPQuery();
    query.ViewAttributes = "Scope=\"Recursive\"";
    PublishingPageCollection pages = pubWeb.GetPublishingPages(query);
    foreach (var page in pages)
    {
        // iterate collection which includes pages in subfolders
    }
}

To suppress this violation in managed code add the following attribute to the method which contains the instruction (available since SPCAF version v5.2). Learn more about SuppressMessage here.

// Important: Ensure to have #define CODE_ANALYSIS at the beginning of your .cs file
[SuppressMessage("SPCAF.Rules.BestPracticesGroup", "SPC050239:DoNotUseGetPublishingPages", Justification = "Provide reason for suppression here")]
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.