To retreive last modified date for the block you may add following tracking method for your block's base class:
public abstract class BaseBlockData : BlockData { public DateTime LastModified { get { var changeTrackable = this as IChangeTrackable; return changeTrackable != null ? changeTrackable.Saved : DateTime.MinValue; } } }
The application I am building is a module which is going to be used on multiple EPiServer sites. The module will not define any block types itself and will only work with generic page and block data types - so I guess this solution will not work for me.
Any other ideas?
You can create then extension method for any block type:
public static class BlockDataExtensions { public static DateTime GetLastModified(this BlockData block) { var changeTrackable = block as IChangeTrackable; return changeTrackable != null ? changeTrackable.Saved : DateTime.MinValue; } }
Okay, I implemented this extension method and I am now able to get the modified date for a block. When I do...
var block = DataFactory.Instance.Get<BlockData>(contentRef); var modified = block.GetLastModified();
... the modfied date is the date of the first version of the block. How do I get the latest version? That is, how do I do DataFactory.Instance.ListVersions() for blocks? Sorry if this is basic stuff, but I can't seem to find anything on this!
var repo = ServiceLocator.Current.Get<IContentVersionRepository>(); var versions = repo.List(...);
This should give you all versions.
Fantastic! Thank you!
Note that it is ServiceLocator.Current.GetInstance and not ServiceLocator.Current.Get
Hi everyone
I read this great post about the editorial cycle in CMS: http://world.episerver.com/blogs/Deane-Barker/Dates/2013/12/The-Editorial-Cycle-in-CMS-7/. It explains well how page versioning works but doesn't mention how block versioning works. Having a content ID, I would like to be able to get the latest version of both pages and blocks and then retrieve their "modified" date. With pages I can do it like this:
With the latestVersion object I can then retrieve a PageData object and use the Saved property to display the modified date.
But what about blocks? DataFactory.Instance.ListVersions() needs a PageReference as parameter - so it only works for pages. And if I am somehow able to retrieve a BlockData object, there is no Saved property on this class, so it does not seem possible to get the modified date for blocks at all.
Can anyone explain whether is possible to retrieve different versions for block and get their modified date? Or explain why it is not?