private void CreateFolderForMonth() { Guid folderTemplateId = Foundation.Models.Models.sitecore.templates.WeaponX.Folders.IBlog_FolderConstants.TemplateId.Guid; var year = DateTime.Now.Year.ToString(); var month = DateTime.Now.Month.ToString("00"); var rootItemId = new ID(BlogFeedLocId); var masterDb = Database.GetDatabase("master"); var parentPubItem = masterDb.GetItem(rootItemId); var yearFolder = BlogImportHelper.EnsureChildFolder(parentPubItem, year, folderTemplateId); var monthFolder = BlogImportHelper.EnsureChildFolder(yearFolder, month, folderTemplateId); }
//Save the Feed to Sitecore private void ProcessNewBlogItem(IBlogItem doc) { string message = string.Format("Creating New Item [docId:{0}] - \"{1}\"", doc.Id, doc.BlogTitle); Sitecore.Diagnostics.Log.Error(message, "RssFeedImport"); IBlogItem blog = null; var masterDb = Database.GetDatabase("master"); var item = masterDb.GetItem("/sitecore/system/Modules/RSSFeedSettings"); Sitecore.Data.Fields.LinkField linkField = item.Fields["BlogLocation"]; Guid folderTemplateId = IBlog_FolderConstants.TemplateId.Guid; DateTime rsspubdate = new DateTime(); if (doc.BlogDisplayDate != null) { rsspubdate = System.Convert.ToDateTime(doc.BlogDisplayDate.ToString()); } ; var year = rsspubdate.Year; var month = rsspubdate.Month; var rootItemId = new ID(new Guid(BlogFeedLocId)); var parentPubItem = masterDb.GetItem(rootItemId); var yearFolder = BlogImportHelper.EnsureChildFolder(parentPubItem, year.ToString(), folderTemplateId); var monthFolder = BlogImportHelper.EnsureChildFolder(yearFolder, month.ToString("00"), folderTemplateId); using (new Sitecore.SecurityModel.SecurityDisabler()) { var itemname = ItemUtil.ProposeValidItemName(doc.BlogTitle); var blogItem = monthFolder.Add(itemname, new TemplateID(IBlogItemConstants.TemplateId)); var db = Sitecore.Configuration.Factory.GetDatabase("master"); if (db != null) { if (blogItem != null) { blogItem.Fields.ReadAll(); blogItem.Editing.BeginEdit(); try { //Should be able to add name here blogItem.Fields["BlogID"].Value = doc.BlogID; blogItem.Fields["BlogTitle"].Value = doc.BlogTitle; blogItem.Fields["BlogAbstract"].Value = doc.BlogAbstract; blogItem.Fields["BlogDisplayDate"].Value = doc.BlogDisplayDate; blogItem.Fields["BlogSourceUrl"].Value = doc.BlogSourceUrl; } catch (Exception ex) { Sitecore.Diagnostics.Log.Error("Error while creating the New Item: " + BlogName + ": " + ex.Message, "RssFeedImport"); } blogItem.Editing.EndEdit(); } } } }