Include expired pages in page list

Vote:
 

Short question: how can I include expired pages in a page list?

#49604
Mar 24, 2011 11:27
Vote:
 

Set the PublishedStatus property to PagePublishedStatus.Ignore

Edit: You may have to set this property from code, if it is not exposed by the webcontrol

#49606
Edited, Mar 24, 2011 11:39
Vote:
 

Yeah, from code it is. I thought I'd tried that one the other day but it looks like it works fine. Thanks!

A follow up question on that one: is it possible to order a page list by two parameters? I'd like to first order them by published/expired and then by name.

#49607
Mar 24, 2011 11:46
Vote:
 

Not as easily. Either attach an event handler to the Filter event and reorder the pages there, or collect the pages yourself, sort them and put them in PageDataCollection which you use as DataSource for the PageList instead of setting the PageLink property.

#49608
Mar 24, 2011 11:49
Vote:
 

Hmm. I'll have to see how I'm going to approach that one. It's a bit further down the road so I guess I'll get back to you on that one... ;)

Thanks a lot!

#49609
Mar 24, 2011 11:53
Vote:
 

LINQ is your friend here. Freehand code for an eventhandler:

var sorted = e.Pages.OrderBy(p => p["Property1"] as string).ThenBy(p => p["Property2"] as string);
e.Pages = new PageDataCollection(sorted);

You'll of course have to adjust for the types of properties etc so it sorts on something interesting. And I'm not sure if e.Pages is read/write, you might have to clear it and loop over sorted (do ToList() on it before clearing e.Pages!) and add the pages one by one.

#49610
Mar 24, 2011 12:00
Vote:
 

Yeah, you're right about LINQ. I never thought about that one. I'll look into it tomorrow or in the beginning of next week. Thanks again!

#49611
Mar 24, 2011 12:11
Vote:
 

Like you said, e.Pages is read only. However, wouldn't it be possible to just set the new PageDataCollection as a DataSource och the PageList and bind it?

#49622
Mar 25, 2011 8:11
Vote:
 

Absolutely, it's a matter of taste. Using getchildren, sorting, filtering and then setting DataSource gives you full control from codebehind, while adding a filter handler to the webcontrol, setting the pagelink and letting it bind itself gives you more flexibility of changing the markup to change behaviour of the list (for example changing the PageLinkProperty property or remove a filter/sort) without recompiling.

Edit: For the e.Pages you can do like this, if someone reading this didn't already gather that:

// Using ToList makes sure the Linq is executed and no longer dependent on e.Pages which will be cleared
var sorted = e.Pages.OrderBy(p => p["Property1"] as string).ThenBy(p => p["Property2"] as string).ToList();

// Clear page collection and re-add in sorted order
e.Pages.Clear();
foreach (var p in sorted)
{
    e.Pages.Add(p);
}

#49623
Edited, Mar 25, 2011 8:59
Vote:
 

That seems to work! Any ideas on how to make them sort by published first and expired last? I'm a total noob when it comes to LINQ. In SQL I did this by converting the expiration date to a bool and making them false if they had expired and then sorted on those first and name after that.

#49626
Edited, Mar 25, 2011 10:42
Vote:
 

Not entirely sure what you want to do, but something like this perhaps:

// Filter out pages not yet published
var pages = ePages.Where(p => p.StartPublish < DateTime.Now);

// Order by publish date (time of day ignored, newest first), expired pages last (no special order),
// then by name if on same date
pages =
    pages.OrderByDescending(p => (p.StopPublish < DateTime.Now) ? p.StartPublish.Date : DateTime.MaxValue)
            .ThenBy(p => p.PageName);

// Execute
pages = pages.ToList();

e.Pages.Clear();
foreach (var page in pages)
{
    e.Pages.Add(page);
}

 


#49627
Mar 25, 2011 11:03
Vote:
 

That did exactly what I wanted. Thank you!

Sorry to say there is one more problem. Like I said earlier the PagePublishedStatus.Ignore didn't work for me when I tried it last week and as I've tried out some different code today and yesterday it has worked sometimes while not other. Turns out the only show when I'm logged into the site (an admin account). Any way around this? I need them to work for every visitor.

#49628
Mar 25, 2011 11:11
Vote:
 

Try setting the RequiredAccess property too, to AccessLevel.NoAccess. Beware that you will also include published pages that the user doesn't have access to. Maybe then it's just simpler to use the GetChildren / DataSource method because you have to do so much of your own logic.

Actually, you're drifting futher away from the intended use of things, by bypassing so many access rights features. Why do you want to show expired pages? If you want to hide them from some other list you could add your own "Expire from main list" DateTime property and just filter on that in your other list instead of messing with the system expiry logic?

#49629
Mar 25, 2011 11:20
Vote:
 

That did the trick. Again, thank you!

I know Im drifting away from the general use of things but I think this is the best way to do it. In short we have a database where our customers pay for there own page on our site. Ones it's expired the page should be removed and only added to the "non-paying" customers. Sort of like the concept of Eniro. I thought that if the pages didn't expire they would still be in our sitemap and be reachable from other places than these lists (e.g. Google and our own page search). There is no worries on this page that a NoAccess would give an unwanted visitor access to something that doesn't concern them.

#49630
Mar 25, 2011 11:40
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.