Skip to content

Instantly share code, notes, and snippets.

@sitefinitySDK
Created March 12, 2014 16:32
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-modify-document-libraries
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Libraries;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.DocumentsAndFiles.ManagingLibraries
{
public partial class LibrariesSnippets
{
private void ModifyDocumentLibraryNativeAPI(Guid documentLibraryId, string newTitle)
{
LibrariesManager librariesManager = LibrariesManager.GetManager();
//Get the library.
DocumentLibrary library = librariesManager.GetDocumentLibraries().Where(b => b.Id == documentLibraryId).FirstOrDefault();
if (library != null)
{
//Modify the library.
library.Title = newTitle;
library.LastModified = DateTime.UtcNow;
library.Urls.Clear();
library.UrlName = Regex.Replace(newTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
//Recompiles and validates the url of the library.
librariesManager.RecompileAndValidateUrls(library);
//Save the changes.
librariesManager.SaveChanges();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment