Reputation: 686
Does anyone know how to get a list of all the items protected (and unprotected them after) in sitecore?
I've googled around but I didn't find any relevant results.
Thanks in advance
This is what I have so far...
var homeItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
foreach (Item item in homeItem.Children)
{
if (item.Locking.IsLocked())
{
//to do
}
}
Unfortunately the item.Locking.IsLocked is not returning if the item is protected or not.
Upvotes: 2
Views: 683
Reputation:
When you press protect or unprotect item this command is called:
item:togglereadonly
This is the part of the method who protect or unprotect item:
public override void Execute(CommandContext context)
{
if (context.Items.Length != 1)
return;
Item obj = context.Items[0];
obj.Editing.BeginEdit();
obj.Appearance.ReadOnly = !obj.Appearance.ReadOnly;
obj.Editing.EndEdit();
Log.Audit((object) this, "Toggle read only: {0}, value: {1}", AuditFormatter.FormatItem(obj), MainUtil.BoolToString(obj.Appearance.ReadOnly));
}
Upvotes: 4
Reputation: 686
Found the solution
var homeItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
foreach (Item item in homeItem.Children)
{
if (item.Appearance.ReadOnly)
{
//stuff here
}
}
Cheers
Upvotes: 2