protected virtual void CreateItemByFields(ID formid, AdaptedResultList fields) { Sitecore.Workflows.WorkflowContextStateSwitcher test = new WorkflowContextStateSwitcher(WorkflowContextState.Enabled); if (StaticSettings.MasterDatabase == null) { Log.Warn("The Create Item action : the master database is unavailable", (object)this); } TemplateItem template = StaticSettings.MasterDatabase.GetTemplate(this.Template); Error.AssertNotNull((object)template, string.Format(ResourceManager.GetString("NOT_FOUND_TEMPLATE"), (object)this.Template)); Item destination = StaticSettings.MasterDatabase.GetItem(this.Destination); Error.AssertNotNull((object)destination, string.Format(ResourceManager.GetString("NOT_FOUND_ITEM"), (object)this.Destination)); var itemName = DateTime.Today.Year.ToString("0000") + "" + DateTime.Today.Month.ToString("00") + "" + DateTime.Today.Day.ToString("00") + "" + fields.ToList()[1].Value; Item obj = ItemManager.CreateItem(itemName, destination, template.ID); NameValueCollection nameValueCollection = StringUtil.ParseNameValueCollection(this.Mapping, '|', '='); obj.Editing.BeginEdit(); foreach (AdaptedControlResult adaptedControlResult in fields) { if (nameValueCollection[adaptedControlResult.FieldID] != null) { string index = nameValueCollection[adaptedControlResult.FieldID]; if (obj.Fields[index] != null) { string str = string.Join("|", new List <string>(FieldReflectionUtil.GetAdaptedListValue(new FieldItem(StaticSettings.ContextDatabase.GetItem(adaptedControlResult.FieldID)), adaptedControlResult.Value, false)).ToArray()); //Check to see if the file being uploaded is an image, if it is then format it correctly //if (str.Contains("sitecore://master/")) //{ //todo:this will not work when using a different template // if (template.OwnFields[3].Type == "Image") // { // string[] result = str.Split('{'); // string id = result[1].Split('}').First(); // str = "<image mediaid=\"{" + id + "}\" />"; // } //} obj.Fields[index].Value = str; if (index == Sitecore.FieldIDs.DisplayName.ToString()) { obj.Name = Sitecore.Data.Items.ItemUtil.ProposeValidItemName(adaptedControlResult.Value); } } else { Log.Warn(string.Format("The Create Item action : the template does not contain field: {0}", (object)index), (object)this); } } } obj.Editing.EndEdit(); }
protected virtual void CreateItemByFields(ID formid, AdaptedResultList fields) { Sitecore.Workflows.WorkflowContextStateSwitcher test = new WorkflowContextStateSwitcher(WorkflowContextState.Enabled); if (StaticSettings.MasterDatabase == null) Log.Warn("The Create Item action : the master database is unavailable", (object)this); TemplateItem template = StaticSettings.MasterDatabase.GetTemplate(this.Template); Error.AssertNotNull((object)template, string.Format(ResourceManager.GetString("NOT_FOUND_TEMPLATE"), (object)this.Template)); Item destination = StaticSettings.MasterDatabase.GetItem(this.Destination); Error.AssertNotNull((object)destination, string.Format(ResourceManager.GetString("NOT_FOUND_ITEM"), (object)this.Destination)); var itemName = DateTime.Today.Year.ToString("0000") + "" + DateTime.Today.Month.ToString("00") + "" + DateTime.Today.Day.ToString("00") + "" + fields.ToList()[1].Value; Item obj = ItemManager.CreateItem(itemName, destination, template.ID); NameValueCollection nameValueCollection = StringUtil.ParseNameValueCollection(this.Mapping, '|', '='); obj.Editing.BeginEdit(); foreach (AdaptedControlResult adaptedControlResult in fields) { if (nameValueCollection[adaptedControlResult.FieldID] != null) { string index = nameValueCollection[adaptedControlResult.FieldID]; if (obj.Fields[index] != null) { string str = string.Join("|", new List<string>(FieldReflectionUtil.GetAdaptedListValue(new FieldItem(StaticSettings.ContextDatabase.GetItem(adaptedControlResult.FieldID)), adaptedControlResult.Value, false)).ToArray()); //Check to see if the file being uploaded is an image, if it is then format it correctly //if (str.Contains("sitecore://master/")) //{ //todo:this will not work when using a different template // if (template.OwnFields[3].Type == "Image") // { // string[] result = str.Split('{'); // string id = result[1].Split('}').First(); // str = "<image mediaid=\"{" + id + "}\" />"; // } //} obj.Fields[index].Value = str; if (index == Sitecore.FieldIDs.DisplayName.ToString()) obj.Name = Sitecore.Data.Items.ItemUtil.ProposeValidItemName(adaptedControlResult.Value); } else Log.Warn(string.Format("The Create Item action : the template does not contain field: {0}", (object)index), (object)this); } } obj.Editing.EndEdit(); }