Validate file type and metadata in Sharepoint Online while uploading

Richard Scannell 366 Reputation points
2021-07-26T10:35:05.517+00:00

Please can someone advise of the best way to pre-validate a file that is being uploaded to a Modern SharePoint Online site :
To check that the filetype is an approved type in a whitelist ( eg pdf , doc or xls ),
To check there is no password (or may be that it has )
To check that required metadata is present, and meets the appropriate rules.

I want to stop the file from being uploaded, with a warning if these business rules are broken.

I am comfortable with the CSOM client context code, and with the C# code to do the actual validation. Its just what is the best way to hook it into the SP Online equivalent of what was called the 'Inserting' event in SharePoint 2010 , as the user is uploading.

The issues I have faced so far are

SharePoint out of the box lets you upload documents and leave 'mandatory' fields empty.
SharePoint out of the box offers only a filetype blacklist (to stop you uploading .bats, .exes etc.). which means you can upload any unsupported file types, or files with no suffixes. I want to implement whitelists, so that we know other users can open open the files.
ContentTypes dont seem to do this.
Webhooks only appear to operate AFTER a file has been successfully uploaded.
Other potential solutions seem to work with 'on premise ' or 'classic' versions not modern online versions

Many thanks in advance

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,909 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,068 questions
{count} votes

Accepted answer
  1. Richard Scannell 366 Reputation points
    2021-07-28T09:39:37.96+00:00

    Hi @Yi Lu_MSFT

    Thank you for your reply. I am happy to use C# and the Client Context model. I am also happy to try NoCode, Custom forms, Javascript, tweaks to the ribbon, function apps, logic apps or in fact any method to achieve these requirements.

    I am not familiar enough with the Microsoft 2021 Modern Application approach in Sharepoint Online , to know which approaches can deliver what we need, and of those which is best practice.

    Will Remote Event receivers do this?

    The problem I have found is that many options look like they MIGHT meet our needs, but the limitations only become clear after I have wasted several hours / days researching them.

    So in summary I need something that is capable of being triggered by an UPLOADING FILE / BEFORE INSERT event, and which can get a handle on the file and its metadata to do some tests, and if necessary cancel the upload with a message.


3 additional answers

Sort by: Most helpful
  1. Yi Lu_MSFT 17,581 Reputation points
    2021-07-28T08:21:06.047+00:00

    Hi @Richard Scannell

    Would you like to use code to achieve these requirements?

    As per my test, those OOB features are by design and we have no way to change them. You could open a service request in Microsoft 365 admin center to get more professional suggestions from Microsoft.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Paul de Jong 726 Reputation points
    2021-07-28T10:20:54.707+00:00

    There are 3rd party apps that offer this functionality (or can be easily extended to address any gaps) but this only works if the users only upload documents using the app. If the documents are added via e.g. OneDrive sync or programmatically then the app's checks are bypassed.

    Have you considered using a drop-off library? at least "incomplete" documents do not end up in your "managed" document libraries.
    Paul

    0 comments No comments

  3. Richard Scannell 366 Reputation points
    2021-07-28T10:46:58.643+00:00

    Hi @Paul de Jong

    Thanks for the reply, I think we are stuck with the architecture we have been given in terms of the lists and folders we use, so I am not sure that we can use the drop off library. Similarly, I dont think there is the appetite to move away from the native SharePoint UI, which excludes the 3rd party products ( Previously I wrote an MVC app, which delivered this for On Prem, but now the requirement is for something that looks more 'SharePointy' ) .

    I have heard terms like Remote Event Receiver, or that you can customise the Sharepoint pages or use addins, but just done know if these are suitable.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.