Created
August 12, 2014 14:53
SF_10.1, SF_10.2, SF_11.0, SF_11.1, SF_11.2, SF_12.0, SF_12.1, SF_12.2, SF_13.0, SF_13.1, SF_13.2, SF_13.3, SF_14.0, SF_14.1, SF_14.2, SF_14.3 - https://docs.sitefinity.com/for-developers-create-folders-inside-libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Threading.Tasks; | |
using Telerik.Sitefinity.Libraries.Model; | |
using Telerik.Sitefinity.Modules.Libraries; | |
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.Folders.ManagingFolders | |
{ | |
public partial class FoldersSnippets | |
{ | |
public static void CreateFolder() | |
{ | |
//gets an instance of the LibrariesManager | |
var manager = LibrariesManager.GetManager(); | |
var title = "ImageAlbumTitle1"; | |
//creates an image album(library) | |
var imagesAlbum = manager.CreateAlbum(); | |
imagesAlbum.Title = title; | |
var url = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); | |
imagesAlbum.UrlName = url; | |
imagesAlbum.ItemDefaultUrl = "/" + url; | |
imagesAlbum.Urls.Add(new LibraryUrlData | |
{ | |
Id = Guid.NewGuid(), | |
Url = imagesAlbum.ItemDefaultUrl, | |
ApplicationName = manager.Provider.ApplicationName | |
}); | |
manager.SaveChanges(); | |
//creates a folder under the album | |
var folder = manager.CreateFolder(imagesAlbum); | |
folder.Title = "FolderTitle"; | |
folder.Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; | |
folder.UrlName = "FolderName"; | |
//always call the SaveChanges() method of the manager in order to commit the operation | |
manager.SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment