1

我希望用户仅在文档库中上传 .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;
       }

}

示例引用了代码。

我的问题是,当我上传非 doc 文件时,它会阻止但系统错误消息不是properties.ErrorMessage.

我该如何解决这个问题?

请帮忙。

4

1 回答 1

0

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

在此处输入图像描述

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

于 2013-07-24T11:17:25.370 回答