public void Create(object obj, string path, string name) { using (new SecurityDisabler()) { var parent = database.GetItem(path); if (parent == null) { return; } var tAttr = obj.GetType().GetCustomAttribute <TemplateAttribute>(); if (tAttr == null) { return; } ID id; Item child; if (ID.TryParse(tAttr.Name, out id)) { child = parent.Add(name, new TemplateID(id)); } else { child = ItemUtil.AddFromTemplate(name, tAttr.Name, parent); } Save(obj, child.ID.ToString()); } }
private Item AddItem(string name, string tid) { var database = Sitecore.Configuration.Factory.GetDatabase(Databasename); if (database == null) { return(null); } var parent = database.GetItem(Parentid); if (parent == null) { return(null); } var username = Sitecore.Context.User.Name.Replace('\\', '_'); var folder = (parent.Axes.GetChild(username)); using (new SecurityDisabler()) { if (folder == null) { folder = ItemUtil.AddFromTemplate(username, "Common/Folder", parent) ?? parent; } return(folder.Add(name, new TemplateID(new ID(tid)))); } }
public void Start(ClientPipelineArgs args) { if (args.IsPostBack) { Database database = Sitecore.Configuration.Factory.GetDatabase( Settings.Instance.ConfigurationDatabase); Assert.IsNotNull(database, "configuration database is null"); Item report = database.GetItem(Current.Context.ReportItem.ID); Assert.IsNotNull(report, "can't find report item"); Sitecore.Context.ClientPage.SendMessage(this, "ASR.MainForm:updateparameters"); using (new Sitecore.SecurityModel.SecurityDisabler()) { Item newItem = ItemUtil.AddFromTemplate(args.Result, "System/ASR/Saved Report", report); using (new EditContext(newItem)) { newItem["parameters"] = Current.Context.ReportItem.SerializeParameters("^", "&"); newItem[Sitecore.FieldIDs.Owner] = Sitecore.Context.User.Name; } } } else { Sitecore.Context.ClientPage.ClientResponse.Input("Enter the name of the new blog entry:", "report name", Sitecore.Configuration.Settings.ItemNameValidation, "'$Input' is not a valid name.", Sitecore.Configuration.Settings.MaxItemNameLength); args.WaitForPostBack(true); } }
private Item addItem(string name, string template, Item parent) { using (new Sitecore.SecurityModel.SecurityDisabler()) { return(ItemUtil.AddFromTemplate(name, template, parent)); } }