0
votes

I am trying to get the children items of a Item.,of which some of the child items applied publish restrictions and there end date had expired. I want to collect all the child items, whether it's end expired or not. when i debugged my code i got only those items which have end date in time. I have used following code

var childItems=item.GetChildren();

the child items collection is collecting only those child items which have there end date in time.

is there any method to collect all the items??

I have asked in sitecore forum, they asked to get child items from master database, but that approach also not working. i have tried following code also.

Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentNode= master.GetItem("ItemNAme");
var childItems=parentNode.GetChildren();

The childitems is only collecting those child items whose end date is not expired Please suggest me some solution for this

Thanks in advance

-Vaibhav

2

2 Answers

2
votes

What you said about going to the master database is correct, as the master contains all versions of all pieces of content, not just publicly published content. I would wrap your code in a SecurityDisabler() in case that is somehow interfering with getting the right items.

using(new SecurityDisabler()) {
    Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
    Item parentNode= master.GetItem("ItemNAme");
    var childItems=parentNode.GetChildren();
}
1
votes

The reason you find this problem is not related to security.

When IsPreview is true (cookie based) and Filtering on the site config is allowed you will not get Items with publishing restrictions. This functionality is from the implementation of the PageEditor Preview where you need to browse the master database as if published items where not visible.

See the answers on Sitecore Publishable flag makes it impossible to GetItem() from Master database