R – Programmatically determine file types in SharePoint

document-librarysharepoint

Is there a way to programmatically determine a file type in SharePoint? I want to limit the types of files that are being uploaded into a document library. I have written an EventReceiver that on ItemAdding conducts the following –

if (!(properties.AfterUrl.Contains(".docx") || properties.AfterUrl.Contains(".pptx") || properties.AfterUrl.Contains(".xlsx") ))

Surely there's a better way to do so?

Best Answer

Blocking file types is only possible at the farm level (through the central admin).

An Event Handler checking the file's extension is the only way to go if you want to be able to administer this at a document library level.

So no, there is no better way of doing this.

Related Topic