在 SharePoint 图片库中自定义上传文件功能 [英] Customizing upload file functionality in SharePoint picture library
本文介绍了在 SharePoint 图片库中自定义上传文件功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能帮我,我想自定义上传功能,我想在其中验证上传的图像类型到图片库
Can anyone help me ,I want to customize upload functionality in which i want to validate the uploaded image type to the picture library
在哪里可以设置我的脚本??任何人都可以建议???
where can i set my script ?? Any one can advise ???
推荐答案
您可能会使用 ItemAdding
.在 ItemAdding
事件方法中,只需在成功上传到库之前检查文档的扩展名.如果文档无效,则通过错误消息
You might be Use ItemAdding
. In ItemAdding
Event Method just check extension of the Document before successfully uploaded to the Library.if unvalid document than through Error message
你的代码是这样的:
protected string[] ValidExtensions = new string[] { "png", "jpeg", "gif"};
public override void ItemAdding(SPItemEventProperties properties)
{
string strFileExtension = Path.GetExtension(properties.AfterUrl);
bool isValidExtension = false;
string strValidFileTypes = string.Empty;
using (SPWeb web = properties.OpenWeb())
{
foreach (string strValidExt in ValidExtensions)
{
if (strFileExtension.ToLower().EndsWith(strValidExt.ToLower()))
{
isValidExtension = true;
}
strValidFileTypes += (string.IsNullOrEmpty(strValidFileTypes) ? "" : ", ") + strValidExt;
}
// Here i am going to check is this validate or not if not than redirect to the
//Error Message Page.
if (!isValidExtension)
{
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = properties.WebUrl + "/_layouts/error.aspx?ErrorText=" + "Only " + strValidFileTypes + " extenstions are allowed";
}
}
}
这篇关于在 SharePoint 图片库中自定义上传文件功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文