Add 3.1 support and check Filename in onBeforeWrite