Sharepoint 2010 SharePoint 2010中事件接收器的自定义错误消息
我希望用户仅在文档库中上载.doc文件 为此,我在VisualStudio2010中开发了一个事件接收器 我的代码如下:Sharepoint 2010 SharePoint 2010中事件接收器的自定义错误消息,sharepoint-2010,event-receiver,Sharepoint 2010,Event Receiver,我希望用户仅在文档库中上载.doc文件 为此,我在VisualStudio2010中开发了一个事件接收器 我的代码如下: public override void ItemAdding(SPItemEventProperties properties) { try { base.ItemAdding(properties); EventFiringEnabled = false; if (!prop
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;
}
}
代码引用自示例
我的问题是,当我上载非文档文件时,它正在阻止,但系统错误消息不是properties.ErrorMessage
中定义的用户友好消息
我如何解决这个问题
请提供帮助。我使用了您在问题中提供的相同代码,我得到自定义错误消息,如下图所示-
请提供您遇到的错误的详细信息。打开您的web.config文件[“C:\inetpub\wwwroot\wss\VirtualDirectories\yourapport\web.config”]并设置CustomError=“On”,然后在web.config文件中选中.set CallStack=“false”;尝试一下。创建了新的解决方案并重写了代码,但仍然出现相同的错误@Amit Thakkarther您的解决方案没有问题,请尝试在web.config文件中设置CallStack=“false”;这应该行得通。但请确保您正在对应用程序的web.config文件应用web.config更改。让我们