Last active
August 29, 2015 14:01
-
-
Save jonathanread/45eb7c6e658e13f12b35 to your computer and use it in GitHub Desktop.
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.Linq; | |
using System.Text.RegularExpressions; | |
using Telerik.Sitefinity.GenericContent.Model; | |
using Telerik.Sitefinity.Libraries.Model; | |
using Telerik.Sitefinity.Lifecycle; | |
namespace Aptera.Sitefinity.Decorators | |
{ | |
public class DocumentsDecorator : LifecycleDecorator | |
{ | |
public DocumentsDecorator (ILifecycleManager manager, LifecycleItemCopyDelegate copyDelegate, params Type[] itemTypes) : base(manager, copyDelegate, itemTypes) | |
{ | |
} | |
public DocumentsDecorator(ILifecycleManager manager, Action<Content, Content> copyDelegate, params Type[] itemTypes) | |
: base(manager, copyDelegate, itemTypes) | |
{ | |
} | |
protected override ILifecycleDataItemGeneric ExecuteOnPublish(ILifecycleDataItemGeneric masterItem, ILifecycleDataItemGeneric liveItem, System.Globalization.CultureInfo culture = null, DateTime? publicationDate = null) | |
{ | |
if (masterItem is Document) | |
{ | |
var documentItem = masterItem as Document; | |
if (documentItem.Library.Id == new Guid("7a571b5d-2460-6bf9-b8a4-ff0000785903") && liveItem == null)//Can also use documentItem.Library.Title.Contains("Form files:") this would cover all file upload widgets, the example targets a specfic form | |
{ | |
string newTitle = documentItem.Title + "_" + Guid.NewGuid().ToString(); | |
documentItem.Title = newTitle; | |
documentItem.UrlName = Regex.Replace(newTitle, @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); | |
} | |
return base.ExecuteOnPublish(documentItem as ILifecycleDataItemGeneric, liveItem, culture, publicationDate); | |
} | |
else | |
{ | |
return base.ExecuteOnPublish(masterItem, liveItem, culture, publicationDate); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment