我添加了此事件接收器(基于我发现的here):
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace PostTravelWizard.PostTravelItemEventReceiver
{
/// <summary>
/// List Item Events
/// </summary>
public class PostTravelItemEventReceiver : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
//GeneratePDF(); <= "The name 'GeneratePDF' does not exist in the current context
}
/// <summary>
/// The list received a context event.
/// </summary>
public override void ContextEvent(SPItemEventProperties properties)
{
base.ContextEvent(properties);
// TODO: What "context event" occurs here? To what event should I respond?
}
}
}
我希望(从客户端/ Javascript)更新列表时,然后在后面的代码中检索这些值以生成PDF文件。我的* .ascx.cs文件中包含以下代码:
public partial class PostTravelWizardWebPartUserControl : UserControl
{
. . .
public void GeneratePDF(PostTravelData ptd)
{
;//bla
}
...但是这不会让我从事件接收器拨打
GeneratePDF()
-失败在当前上下文中不存在名称“ GeneratePDF”
为什么?我该如何纠正此问题?
最佳答案
GeneratePDF
是PostTravelWizardWebPartUserControl
类的实例方法。为了从PostTravelItemEventReceiver
调用它,您必须创建PostTravelWizardWebPartUserControl
的实例或将方法(GeneratePDF
)设置为static
。
情况1
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
new PostTravelWizardWebPartUserControl().GeneratePDF();
}
情况二
public partial class PostTravelWizardWebPartUserControl : UserControl
{
public static void GeneratePDF(PostTravelData ptd)
{
;//bla
}
}
public class PostTravelItemEventReceiver : SPItemEventReceiver
{
base.ItemAdded(properties);
PostTravelWizardWebPartUserControl.GeneratePDF();
}