Help shape the future of CMS PaaS release notes! Take this quick survey and share your feedback.
Help shape the future of CMS PaaS release notes! Take this quick survey and share your feedback.
Product version: |
EPiServer CMS 5 R1 |
---|---|
Document version: |
1.0 |
Document creation date: |
24-11-2006 |
Document last saved: |
12-09-2007 |
The base for File Event subscription is the UnifiedFile and UnifiedDirectory classes. They are abstraction classes of the underlying file system and the facade for EPiServer CMS 5 and file management.
UnifiedFile triggers events (both pre and post events) to subscribers when a file is
UnifiedDirectory triggers events (both pre and post events) to subscribers when
Since UnifiedFile and UnifiedDirectory are highly abstract classes in the EPiServer CMS 5 object hierarchy, there is no knowledge of who (logged-in EPiServer CMS 5 user) performed the operation. This makes more sense since underlying FileSystems (such as NativeFileSystem) can have a non-EPiServer CMS 5 user manipulating files directly outside the admin UI. It is not recommended to use the local file directory used by EPiServer CMS 5 directly since other functionality may rely on events being triggered, for example Workflows.
Below is a sample code snippet to illustrate how to subscribe on File events. The example class is a singleton instance storing the list of events (as strings) triggered by UnifiedFile, in a real live scenario the listener for events might be implemented differently.
public class Subscriber
{
private static Subscriber instance = null;
private static IList<string> events = new List<string>();
static Subscriber()
{
UnifiedFile.UnifiedFileMoved += new UnifiedFileEventHandler<UnifiedVirtualPathEventArgs>(UnifiedFile_FileMoved);
}
void UnifiedFile_FileMoved(UnifiedFile sender,
UnifiedVirtualPathEventArgs args)
{
events.Add("File moved from: " +
args.VirtualPath +
" to:" +
args.NewVirtualPath);
}
public static Subscriber Instance
{
get
{
if (instance == null)
instance = new Subscriber();
return instance;
}
}
public IList GetEvents()
{
return events;
}
}