/// <summary> /// Stores the given tag into the content repository as Tag node type. /// </summary> /// <param name="tag">Tag to store.</param> /// <param name="path">The folder path in repository, where you want to save the stored Tag node.</param> public static void AddToRepository(string tag, string path) { tag = tag.ToLower(); var parentNode = Node.LoadNode(path); var subFolderName = GetTagName(tag); subFolderName = subFolderName.Length > 1 ? subFolderName.Substring(0, 2).Trim() : subFolderName; var fullPath = RepositoryPath.Combine(path, subFolderName); if (!Node.Exists(fullPath)) { var cnt = Content.CreateNew("Folder", parentNode, subFolderName); cnt.Save(); parentNode = cnt.ContentHandler; } else { parentNode = Node.LoadNode(fullPath); } var tagfileName = GetTagName(tag); var newTag = Content.CreateNew("Tag", parentNode, UrlNameValidator.ValidUrlName(tagfileName)); newTag["DisplayName"] = tag.ToLower(); newTag["TrashDisabled"] = true; newTag.Save(); }
/// <summary> /// Stores the given tag into the content repository as Tag node type. /// </summary> /// <param name="tag">Tag to store.</param> /// <param name="path">The folder path in repository, where you want to save the stored Tag node.</param> public static void AddToRepository(string tag, string path) { tag = tag.ToLower(); var parentNode = Node.LoadNode(path); var subFolderName = ContentNamingHelper.GetNameFromDisplayName("", tag); subFolderName = subFolderName.Replace('.', '_').Replace('"', '_').Replace('\'', '_'); subFolderName = subFolderName.Length > 1 ? subFolderName.Substring(0, 2) : subFolderName; var fullPath = RepositoryPath.Combine(path, subFolderName); if (!Node.Exists(fullPath)) { var cnt = ContentRepository.Content.CreateNew("Folder", parentNode, subFolderName); cnt.Save(); parentNode = cnt.ContentHandler; } else { parentNode = Node.LoadNode(fullPath); } var tagfileName = ContentNamingHelper.GetNameFromDisplayName("", tag); tagfileName = tagfileName.Replace('.', '_').Replace('"', '_').Replace('\'', '_'); var newTag = ContentRepository.Content.CreateNew("Tag", parentNode, UrlNameValidator.ValidUrlName(tagfileName)); newTag["DisplayName"] = tag.ToLower(); newTag["TrashDisabled"] = true; newTag["CreationDate"] = DateTime.Now; newTag.Save(); }