문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

If you are really interested in restricting certain types of files, I would recommend to go beyond file's extension or mime types and inspect file's content to determine its nature, which is what IE and Firefox do.

(BTW, there's an IE API whose name I cannot remember right now that gives you the mime type of a file after inspecting it.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top