2

I have 3 items in a folder based on the same template. Is there any functionality provided by Sitecore to prevent these items from being moved to another folder accidentally or deliberatively? Or we can apply any validation on the template like if an item is created on the base of this template it cannot be moved. You can only edit, copy or delete it. Thanks for the help.

2
  • Can you add a subscriber to the item:moving event? Mar 4 '19 at 14:30
  • Yeah did that, thanks for the help @MichaelWest
    – PSS
    Mar 4 '19 at 15:43
4

There is nothing like that out of the box in Sitecore. But you can easily create such a functionality on your own:

  1. Create a new template with one field only - checkbox "Cannot be moved"
  2. Add your handler to <event name="item:moving"/>
  3. In the handler code cancel the event if the checkbox is checked.

I haven't tested the code but something like this should do the trick:

  protected void OnItemMoving(object obj, EventArgs args)
  {
      if (JobContext.IsJob && JobContext.Job.Category == "publish")
          return;

      SitecoreEventArgs evt = args as SitecoreEventArgs;
      Item item = Event.ExtractParameter(args, 0) as Item;

      if (MainUtil.GetBool(item["Cannot be moved"], false))
        this.CancelEvent(evt);
  }

And as Dan Sinclair suggested:

You may want to apply field level security to that Cannot be moved field, too, to ensure that savvy content editors don't work around it. :)

5
  • You may want to apply field level security to that Cannot be moved field, too, to ensure that savvy content editors don't work around it. :) Mar 4 '19 at 14:33
  • @DanSinclair smart! I added your comment to the answer Mar 4 '19 at 14:35
  • @MarekMusielak This is working great. Thanks for the help guys.
    – PSS
    Mar 4 '19 at 15:42
  • I'm glad I could help. If this answer worked for you, you may want to mark it as "Accepted" so further visitors will know that it works. Mar 4 '19 at 15:54
  • @MarekMusielak Sure.
    – PSS
    Mar 4 '19 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.