1
votes

With Umbraco, is there any way to trigger within code any time a field is updated in a document?

I have an umbraco api that is using data that is stored in a table structure. This data is only used for calculations and not exposed directly on any page, but I want the back end users to be able to modify it. I have code that will take a CSV file and upload the data to the table. I've created a data type that only has one field that is an Upload field. I want to trigger the table update whenever that file is updated. The alternative is to have some sort of filewatcher monitoring the media folder for this particular file, this is the way I'm leaning if umbraco doesn't have a solution.

1

1 Answers

1
votes

Yes, there is an API available which you can use. For Umbraco v6.1+ refer to the Saved event in the ContentService, as described here.

You can register your own event handler using the ApplicationEventHandler interface:

public class RegisterEvents : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication,       ApplicationContext applicationContext)
    {
       Document.Saved += DocumentSaved;
    }

    private void DocumentSaved(Document sender, PublishEventArgs e)
    {
      // check your document type and fields to see if it has changed
    }
}