gpt4 book ai didi

sharepoint - 如何在工作流事件 (SharePoint) 中获取上下文项

转载 作者:行者123 更新时间:2023-12-04 01:33:07 26 4
gpt4 key购买 nike

我正在为 sharepoint 工作流编写自定义事件,但我不知道如何使用当前的工作流项目、SPWeb 或 SPSite。

我看到http://blogs.microsoft.co.il/blogs/davidbi/archive/2008/07/21/How-to-get-the-context-item-in-workflow-activity-sharepoint.aspx但是这个解决方案的 xml 例程对我来说太糟糕了。

也许还有另一种纯代码解决方案来获取工作流事件中的上下文项?

最佳答案

这个问题的答案是几个步骤:

  • 将属性添加到您的自定义事件 .cs
  • 链接您的 .actions 文件中的属性(因此 SPD 知道如何映射到您的属性)
  • 使用代码中的属性

  • 第 1 步 :这是属性的代码(我的类名为 GetEmails,您需要将其重命名为您的类):
    public static DependencyProperty __ContextProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(GetEmails));

    [Description("The site context")]
    [Category("User")]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public WorkflowContext __Context
    {
    get
    {
    return ((WorkflowContext)(base.GetValue(GetEmails.__ContextProperty)));
    }
    set
    {
    base.SetValue(GetEmails.__ContextProperty, value);
    }
    }

    public static DependencyProperty __ListIdProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__ListId", typeof(string), typeof(GetEmails));

    [ValidationOption(ValidationOption.Required)]
    public string __ListId
    {
    get
    {
    return ((string)(base.GetValue(GetEmails.__ListIdProperty)));
    }
    set
    {
    base.SetValue(GetEmails.__ListIdProperty, value);
    }
    }

    public static DependencyProperty __ListItemProperty = System.Workflow.ComponentModel.DependencyProperty.Register("__ListItem", typeof(int), typeof(GetEmails));

    [ValidationOption(ValidationOption.Required)]
    public int __ListItem
    {
    get
    {
    return ((int)(base.GetValue(GetEmails.__ListItemProperty)));
    }
    set
    {
    base.SetValue(GetEmails.__ListItemProperty, value);
    }
    }

    public static DependencyProperty __ActivationPropertiesProperty = DependencyProperty.Register("__ActivationProperties", typeof(Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties), typeof(GetEmails));

    [ValidationOption(ValidationOption.Required)]
    public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties __ActivationProperties
    {
    get
    {
    return (Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties)base.GetValue(GetEmails.__ActivationPropertiesProperty);
    }
    set
    {
    base.SetValue(GetEmails.__ActivationPropertiesProperty, value);
    }
    }

    第 2 步 :然后在您的 .actions 文件中将这些属性的映射添加到您的块中(注意 __ListID、__ListItem、__Context 和 __ActivationProperties 的条目):
    <Action Name="[DESCRIPTION OF YOUR ACTION]"
    ClassName="[Your.Namespace.Goes.Here].GetEmails"
    Assembly="[yourDLLName], Version=1.0.0.0, Culture=neutral, PublicKeyToken=0bfc6fa4c4aa913b"
    AppliesTo="all"
    Category="[Your Category Goes Here]">
    <RuleDesigner Sentence="[blah blah blah]">
    <FieldBind Field="PeopleFieldName" Text="people field" Id="1"/>
    <FieldBind Field="Output" Text="emailAddress" Id="2" DesignerType="parameterNames" />
    </RuleDesigner>
    <Parameters>
    <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext" Direction="In" />
    <Parameter Name="__ListId" Type="System.String, mscorlib" Direction="In" />
    <Parameter Name="__ListItem" Type="System.Int32, mscorlib" Direction="In" />
    <Parameter Name="PeopleFieldName" Type="System.String, mscorlib" Direction="In" />
    <Parameter Name="Output" Type="System.String, mscorlib" Direction="Out" />
    <Parameter Name="__ActivationProperties" Type="Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties, Microsoft.SharePoint" Direction="Out" />
    </Parameters>
    </Action>

    第 3 步 :
    下面是一个执行函数的例子:
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext provider)
    {
    Output = string.Empty;

    try
    {
    SPWeb web = __Context.Web;
    // get all of the information we currently have about the item
    // that this workflow is running on
    Guid listGuid = new Guid(__ListId);
    SPList myList = web.Lists[listGuid];
    SPListItem myItem = myList.GetItemById(__ListItem);

    //...
    }
    catch (Exception e)
    {
    //...
    }

    return ActivityExecutionStatus.Closed;
    }

    关于sharepoint - 如何在工作流事件 (SharePoint) 中获取上下文项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1243736/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com