Overview

I've recently hit an issue where some custom controls have been generating exceptions when unpublished pages exist in an EPiServer site.  In these cases, the relevant (required) properties have null values.

Context

Rather than using the standard EPiServer property controls, these pages use ASP.NET data-binding and custom controls that access the required properties of EPiServer PageData objects.  They are being viewed in the editing interface by a logged-in user with full permissions.  The PageData object is sourced using a FindPagesWithCriteria operation.

Problem

Any of the custom page properties accessed using PageData["PropertyName"] (in C#) return null preventing the display of any useful information and causing exceptions in various cases, such as in sorting operations and date formatting.

Cause

EPiServer does not automatically load the properties for unpublished pages.  You have to manually instruct EPiServer to load them.

Solution

Check to see if the page is unpublished and (optionally) whether the user has appropriate access rights.  If appropriate, load the full version of the unpublished page and possibly store it in a PageDataCollection:

   1: public static PageDataCollection LoadUnpublishedAsNecessary(PageDataCollection pdc, 
bool clearSource)
   2: {
   3:     PageDataCollection pdc2 = new PageDataCollection();
   4:  
   5:     foreach (PageData p in pdc)
   6:     {
   7:         if (p.PendingPublish)
   8:         {
   9:             AccessLevel l = p.QueryAccess();
  10:             if (((l & AccessLevel.Edit) == AccessLevel.Edit) ||
  11:                  ((l & AccessLevel.Publish) == AccessLevel.Publish))
  12:             {
  13:  
  14:                 PageReference r = new PageReference(p.PageLink.ID, true);
  15:                 pdc2.Add(EPiServer.Global.EPDataFactory.GetPage(r));
  16:                 continue;
  17:             }
  18:         }
  19:         pdc2.Add(p);
  20:     }
  21:     if (clearSource) pdc.Clear();
  22:  
  23:     return pdc2;
  24: }

References

Versions

  • EPiServer 5, EPiServer 4.6

Metadata


Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Tuesday, April 01, 2008 11:45 AM | in EPiServer ASP.NET .NET Software Development

Comments

No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 4 and 4 and type the answer here: