开发者

Programmatically determine file types in SharePoint

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 -

开发者_C百科

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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜