【问题标题】:Custom Error Message for Event Receiver in SharePoint 2010SharePoint 2010 中事件接收器的自定义错误消息
【发布时间】:2013-07-24 19:17:25
【问题描述】:

我希望用户只上传文档库中的 .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 中定义的用户友好。

我该如何解决这个问题?

请帮忙。

【问题讨论】:

    标签: sharepoint-2010 event-receiver


    【解决方案1】:

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

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

    【讨论】:

    • 打开您的 web.config 文件 ["C:\inetpub\wwwroot\wss\VirtualDirectories\YourAppPort\web.config"] 并设置 CustomError = "On" 然后检查。
    • 在 web.config 文件中设置 CallStack="false";试一试。
    • 创建了新的解决方案并重写了代码,但仍然出现同样的错误......@Amit Thakkar
    • 你的解决方案没有问题,尝试在web.config文件中设置Call​​Stack="false";这应该有效。但请确保将 web.config 更改应用于应用程序的 web.config 文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    • 2019-01-03
    • 1970-01-01
    相关资源
    最近更新 更多