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.
[SuppressMessage("SPCAF.Rules.BestPracticesGroup", "SPC050239:DoNotUseGetPublishingPages", Justification = "Provide reason for suppression here")]