以编程方式确定 SharePoint 中的文件类型
有没有办法以编程方式确定 SharePoint 中的文件类型?我想限制上传到文档库的文件类型。我编写了一个 EventReceiver,它在 ItemAdding 上执行以下操作 -
if (!(properties.AfterUrl.Contains(".docx") ||properties.AfterUrl.Contains(".pptx") ||properties.AfterUrl.Contains(". xlsx") ))
当然有更好的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阻止文件类型只能在场级别(通过中央管理)。
如果您希望能够在文档库级别对其进行管理,则检查文件扩展名的事件处理程序是唯一的方法。
所以不,没有更好的方法来做到这一点。
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.
如果您确实有兴趣限制某些类型的文件,我建议您超越文件的扩展名或 mime 类型,并检查文件的内容以确定其性质,这就是 IE 和 Firefox 会这样做。
(顺便说一句,有一个 IE API,我现在记不起它的名字,它在检查文件后为您提供文件的 mime 类型。)
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.)