Last active
October 18, 2024 19:50
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-documents
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.IO; | |
using System.Text.RegularExpressions; | |
using Telerik.Sitefinity.Libraries.Model; | |
using Telerik.Sitefinity.Workflow; | |
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.MediaModules.DocumentsAndFiles.ManagingDocuments | |
{ | |
public partial class DocumentsSnippets | |
{ | |
public static void ModifyDocumentFluentAPI(Guid masterDocumentId, string newTitle, Stream documentStream, string documentFileName, string documentExtension) | |
{ | |
var count = 0; | |
App.WorkWith().Documents().Where(i => i.Id == masterDocumentId).Count(out count); | |
if (count > 0) | |
{ | |
App.WorkWith().Document(masterDocumentId).CheckOut().Do(document => | |
{ | |
document.Title = newTitle; | |
document.LastModified = DateTime.UtcNow; | |
document.Urls.Clear(); | |
document.UrlName = Regex.Replace(newTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); | |
document.MediaFileUrlName = Regex.Replace(documentFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); | |
}).UploadContent(documentStream, documentExtension).CheckIn().Publish().SaveChanges(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment