SharePoint 2010中的事件接收器的自定义错误消息

时间:2013-07-24 08:36:47

标签: sharepoint-2010 event-receiver

我希望用户只在文档库中上传.doc文件。

为此,我在Visual Studio 2010中开发了一个事件接收器。

我的代码如下:

public override void ItemAdding(SPItemEventProperties properties)
{
       try
       {

           base.ItemAdding(properties);
           EventFiringEnabled = false;

           if (!properties.AfterUrl.EndsWith("doc"))
           {
               properties.ErrorMessage = "You are allowed to updload only .doc files";
               properties.Status = SPEventReceiverStatus.CancelWithError;
               properties.Cancel = true;

           }
       }
       catch (Exception ex)
       {
           properties.Status = SPEventReceiverStatus.CancelWithError;
           properties.ErrorMessage = ex.Message.ToString();
           properties.Cancel = true;
       }

}

代码来自this示例。

我的问题是,当我上传非doc文件时,它会阻止,但系统错误消息不是properties.ErrorMessage中定义的用户友好。

我该如何解决这个问题?

请帮忙。

1 个答案:

答案 0 :(得分:0)

我使用了您在问题中提供的相同代码,我收到显示的自定义错误消息,如下图所示 -

enter image description here

请提供您所遇到的错误的详细信息。