public static GetItem ( Database db, string path ) : Item | ||
db | Database | The Sitecore db to search for the item. |
path | string | The path of the item to find. |
리턴 | Item |
/// <summary> /// Creates an alphabet folder structure under the passed in parent. This will also inlcude 123 as a folder /// for handling items that start with numbers. /// </summary> /// <param name="parentItem">The parent item.</param> /// <param name="folderTemplate">The folder template.</param> /// <param name="upperCase">if set to <c>true</c> make the letter folder name upper case.</param> public static void CreateAlphabetFolderStructure(Item parentItem, TemplateItem folderTemplate, bool upperCase) { if (parentItem == null || folderTemplate == null) { return; } Database masterDb = Factory.GetDatabase("master"); using (new SecurityDisabler()) { foreach (string letter in alphabetFolderNames) { //If we are supposed to make the folder name upper case, do so string folderName = letter; if (upperCase) { folderName = folderName.ToUpper(); } //Only add the folder if it does not already exist, this way this method can be used to fill // in missing folders in an already existing partial alpha folder structure. string letterFolderPath = string.Format("{0}/{1}", parentItem.Paths.Path, folderName); Item alphaFolder = SitecoreItemFinder.GetItem(masterDb, letterFolderPath); if (alphaFolder == null) { parentItem.Add(letter.ToUpper(), folderTemplate); } } } }
/// <summary> /// Serializes a single item to a file on disk. /// </summary> /// <param name = "folderPath">The folder path where the serialized item will be written to.</param> /// <param name = "itemGuid">The item GUID.</param> /// <param name = "db">The db.</param> public static void SerializeItem(string folderPath, string itemGuid, Database db) { Item item = SitecoreItemFinder.GetItem(db, itemGuid); if (item == null) { return; } item.SerializeItem(folderPath); }
/// <summary> /// Serializes the items of a specified template recursively from the passed in root down to a file on disk. /// </summary> /// <param name = "folderPath">The folder path where the serialized items will be written to.</param> /// <param name = "rootGuid">The root GUID.</param> /// <param name = "templateName">Name of the template.</param> /// <param name = "db">The db.</param> public static void SerializeItemsOfTemplate(string folderPath, string rootGuid, string templateName, Database db) { Item contentRoot = SitecoreItemFinder.GetItem(db, rootGuid); if (contentRoot != null) { SerializeItemList(folderPath, (from Item child in contentRoot.Axes.GetDescendants() where child.Template.Name == templateName select child).ToList()); } }