Just to clearify, I'm using the GetPages() method in DataFactory and binds the collection to the pagelist. All properties are null, except built-in ones, in the collection GetPages() returns.
Use PageVersion.List to get hold of the version-specific references to the page. If there are several verisons I think they are ordered with the newest version first in the returned array. Then use GetPage with the versioned reference instead of the original page reference.
In my case there is only one version, the non published one. I'm creating a new page and just saves it.
In CMS 5 I think I used this code to get all children (published/not published)
public PageDataCollection GetChildrenAndNotPublished(PageReference pageRef, string langID)
{
PageDataCollection result = EPiServer.DataFactory.Instance.GetChildren(pageRef, new LanguageSelector(langID));
PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();
PropertyCriteria pubCriteria = new PropertyCriteria();
pubCriteria.Condition = EPiServer.Filters.CompareCondition.Equal;
pubCriteria.Name = "PagePendingPublish";
pubCriteria.Type = PropertyDataType.Boolean;
pubCriteria.Value = true.ToString();
pubCriteria.Required = true;
criterias.Add(pubCriteria);
PropertyCriteria pubCriteria2 = new PropertyCriteria();
pubCriteria2.Condition = EPiServer.Filters.CompareCondition.Equal;
pubCriteria2.Name = "PageParentLink";
pubCriteria2.Type = PropertyDataType.PageReference;
pubCriteria2.Value = pageRef.ToString();
pubCriteria2.Required = true;
criterias.Add(pubCriteria2);
PageDataCollection matches = DataFactory.Instance.FindPagesWithCriteria(pageRef, criterias, langID);
foreach (PageData match in matches)
{
PageReference realReference = new PageReference(match.PageLink.ID, true);
PageData unPublishedPageData = EPiServer.DataFactory.Instance.GetPage(realReference,
new LanguageSelector(langID));
result.Add(unPublishedPageData);
}
return result;
}
Guess I can only check all pages and if they are not published just get them using new PageReference(match.PageLink.ID, true);
The problem isn't that non-published pages shows up or not in the pagelist. The problem is that all properties are not populated with data, even if it has data. Only built-in properties gets populated with data.
Will PageReference(match.PageLink.ID, true); really solve that problem? Then I have to loop thru all my pagereferences... Performance-wise I guess that the new GetPages() is much faster.
Seems like a bug to me if not GetPage and GetPages behaves the same way.
But I'll have to check tomorrow if getting the pages with any version flag set to true makes any difference.
This has been reported as a bug http://world.episerver.com/Support/bug-list/#bug,EPiServer CMS,74317,jS0N%2fMhWc1DmNtx5OZX%2bmmcRJqI%3d
http://world.episerver.com/Support/bug-list/#bug,EPiServer CMS,74317,jS0N%2fMhWc1DmNtx5OZX%2bmmcRJqI%3dIt has been reported as a bug (actually several times) but I'm not sure that we'll fix it. The problem is that published data lies in tblPage and tblProperty while unpublished pages/versions lies in tblWorkPage and tblWorkProperty. When a GetPage is executed in the database without any specific version requested it will try to fetch the data from the tblPage/tblProperty tables. For non-published pages there is data in tblPage but not tblProperty and that's why some metadata is returned but not custom properties.
I agree that it's a flaw and have been forced to do quite alot work arounds over the years when working in the UI where we often work with unpublished versions. But fixing this would require checking state in tblProperty and then fetching from either tblPage/tblProperty or tblWorkPage/tblWorkProperty which would complicate the logic and affect performance.
In our internal discussions we have been leaning on leaving it as it it as we consider performance more important than the actual glitch in this case. What are your opinions?
Hi Linus,
Thanks for the answer. I also think performance is more important and in my case I can really filter out un-published pages instead. Maybe you could add an overload to GetPages to filter out these pages? Or do you recommend to filter them out manually affterwards? Performance wise I guess it would be better to not fetch them at all.
I also think this behaviour i quite strange, maybe not if you only have "presentational" properties but if you have "logical" ones, like "DontShowMeInThisList" it can get quite messy.
For your information. This has now been fixed and will be available in our next major release.
With the fix data for page type properties for unpublished are always loaded regardless if the pages is loaded through GetPages, GetChildren or GetPage (before the fix data was loaded correctly for GetPage but wrongly for GetPages and GetChildren).
This also solves the related issues for copy/export of unpublished pages where data where not copied/exported.
If you're logged in as an editor non published pages shows up pagelists, if you want to. But only built-in properties, e.g. PageName, have values. Is this by design? Is there a way to populate all defined properties too?