public void OnItemCreating(object sender, EventArgs args) { using (new SecurityDisabler()) { ItemCreatingEventArgs arg = Event.ExtractParameter(args, 0) as ItemCreatingEventArgs; if (arg.Item != null) { var item = arg.Item; if (item.Parent != null) { //see if the item is being placed under a Navigation Item type or under the Navigation folder if (item.Parent.TemplateName == "Navigation Item" || item.ParentID.ToString() == "{6ED240C9-1B69-48E2-9FD9-6C45CD8ABE63}") { if (item.TemplateName != "Navigation Item") { using (new Sitecore.SecurityModel.SecurityDisabler()) { ((SitecoreEventArgs)args).Result.Cancel = true; SheerResponse.Alert("Sorry, you can only add items based on the \"Navigation Item\" template here"); } } } } } } }
/// <summary> /// Responds to Sitecore new item creation, cloning an item, and duplicating an item (either via the UI or API) /// </summary> /// <param name="sender"></param> /// <param name="args">Param index 0 contains the ItemCreatingEventArgs: Contains item ID, name, master and template IDs, parent item</param> protected void OnItemCreating(object sender, EventArgs args) { Assert.IsTrue(args != null, "args != null"); if (args != null && _auditItemCreating) { using (new SecurityDisabler()) { ItemCreatingEventArgs arg = Event.ExtractParameter(args, 0) as ItemCreatingEventArgs; Assert.IsTrue(arg != null, "arg != null"); if ((arg != null) && (Sitecore.Context.Site.Name == "shell") && (_preventDuplicateNames)) { foreach (Item currentItem in arg.Parent.GetChildren()) { if ((arg.ItemName.Replace(' ', '-').ToLower() == currentItem.Name.ToLower()) && (arg.ItemId != currentItem.ID)) { arg.Cancel = true; Sitecore.Context.ClientPage.ClientResponse.Alert("Name \"" + currentItem.Name + "\" is already in use. Please use another name for the item."); return; } } } if (arg != null && ShouldAudit(arg.Parent)) { Item t = arg.Parent.Database.Items[arg.TemplateId]; string templateName = t != null ? t.Name : arg.TemplateId.ToString(); Log(string.Format("CREATE: {0}:{1}/{2}, id: {3}, template: {4}", arg.Parent.Database.Name, arg.Parent.Paths.Path, arg.ItemName, arg.ItemId.ToString(), templateName)); } } } }
protected virtual void OnItemCreating(object sender, SitecoreEventArgs eventArgs, ItemCreatingEventArgs itemCreating) { throw new NotImplementedException(); }