Check filename and file extension on upload in an event handler

Hi all, I need to run some checks on uploaded documents based on file extension and filename

We're using the Classic Web client

Basic code below, it works when it's a Precondition in a workflow, using either Desktop or Classic Web clients

But, I now need to move it to an Event Handler for reasons (BeforeFileUpload, or BeforeCreateNewObjectFinalize), and when I do, it stops working in Classic Web, although continues to work in Desktop

' Test filetype on upload to Reports document classes. Precondition in Reports workflow
' Needs an IF to allow/disallow certain filetypes if implemented

Dim oObjectFiles : Set oObjectFiles = Vault.ObjectFileOperations.GetFiles(ObjVer)
Dim oObjectFile : Set oObjectFile = oObjectFiles.Item(1)
Dim strExtension
strExtension = oObjectFile.Extension

' Get file extension

Err.Raise MFScriptCancel, "Filename: '" & oObjectFile.Title & ". Filetype: '" & strExtension & "'"

It's this part

Dim oObjectFiles : Set oObjectFiles = Vault.ObjectFileOperations.GetFiles(ObjVer)
Dim oObjectFile : Set oObjectFile = oObjectFiles.Item(1)

It doesn't work when I'm uploading as a single file (not MFD) into a doc class, using the Classic Web client. I think perhaps the GetFiles isn't the right approach for a single file, or the actual file doesn't "exist" yet on the vault at the point I'm trying to run this... not sure
Any ideas please?
Many thanks
  • Hi, only Desktop and Classic Web

    I know the stance on Classic Web, but unfortunately we're in production and using that for all users

    Many thanks

  • You say "Desktop" - do you mean Classic Desktop or the new/latest desktop client?

    The classic web operates differently in some places, sometimes due to the nature of the fact it's running in the web (and sometimes not).  As a result I have a recollection that the file upload event handlers do run differently, but I have not developed against the classic web client in several years.  I guess many others do not support this either, so you may struggle with knowledge here.  As an "official" response I should guide you to test in the new clients and, if these operate as you want, think about how you migrate across to them over time.  I appreciate that's not the most helpful though.

    You've mentioned that it "does not work".  Maybe describe a little about how it "does not work" when in the beforecreatenewobjectfinalize event handler; does it error, or...?

  • Classic desktop vs new desktop, not sure. It is M-Files Online 24.8.13981.4, if that helps clarify

    It looks like this https://help.m-files.com/news/whats-new/new-m-files-desktop/

    And the error message, sorry I'd forgotten that:

    Object marked to be available offline (The parameter is incorrect.

    ATLHelper.h, 489, The parameter is incorrect. (0x80070057)
    (M-Files 24.8.13981.4 2025-07-01T10:57:40.969Z)

    (0027))
    Error reference ID: 04ab4a72-b470-419a-95bd-542788bce583
  • Okay, that's the new desktop.  In which case this probably already works in the new web as well.

    You've not included anything that lets me know what the line is, but let's assume it's the GetFiles method.  The only possible guidance I have is to use GetFilesForModificationInEventHandler instead: M-Files API - GetFilesForModificationInEventHandler Method

    In addition to the above I would also caution against writing lots of new VBScript, as Microsoft has announced that this will be removed from future versions of Windows.  A better, longer-term, approach might be to use the Vault Application Framework.

  • Additionally, as I said earlier, you may struggle to get a lot of people replying to this as the classic web client has been considered legacy for some time now.  The reality of that is that, assuming it works correctly in the new web client, it's difficult to maintain knowledge around some of these edge cases.

    I notice from your profile that it states that you're a partner, but I cannot see any details as to your company name.  I assume that's on purpose.  For now I will maybe highlight that as a partner you can reach out to the support team for an "implementation support request" which may be a way to get more targeted support.  Alternatively your partner account manager may be able to assist further.