简体   繁体   English

获取实例化工作流的SharePoint列表数据?

[英]Get SharePoint list data that instantiated workflow?

So I'm creating a SharePoint 2010 project in Visual Studio that contains a Sequential Workflow (Farm Solution only) item that is associated with a certain list so that when an item is added to the list the workflow starts. 因此,我在Visual Studio中创建一个SharePoint 2010项目,该项目包含与某个列表关联的顺序工作流(仅限场解决方案)项,以便在项目添加到列表时工作流启动。

My question is, say an item was added in the following format: 我的问题是,说一个项目是按以下格式添加的:

Name | 名称| Email 电子邮件

Dave | 戴夫| dave@dave.com dave@dave.com

Is there a way, programatically, to store this data in variables? 有没有办法以编程方式将这些数据存储在变量中? As is, without using any hardcoded indexes or anything, just programatically have it so that I can pull this data and store it in two C# variables (int iD, string emailAddress) and the workflow knows which list item kicked it off? 按原样,不使用任何硬编码索引或任何东西,只需以编程方式获取它,以便我可以提取这些数据并将其存储在两个C#变量(int iD,string emailAddress)中,并且工作流知道哪个列表项被踢掉了?

At the moment the way I'm doing it is: 目前我正在这样做的方式是:

using (SPWeb oWeb = SPContext.Current.Web) {
    SPList oList = web["List Name"];
    string name = list.Items[(oList.ItemCount - 1)]["Name"].ToString();
}

But I'd rather not use indexers as there's a chance that the index is off if another item is added rapidly and if the list is reordered then ... disaster. 但我宁愿不使用索引器,因为如果快速添加另一个项目并且列表重新排序然后......灾难,索引可能会关闭。

Thanks in advance! 提前致谢!

Solved it guys! 解决了它们! Very stupid of me to overlook this, but here is the solution: 非常愚蠢的我忽略了这一点,但这是解决方案:

C# creates a workflowProperties variable for you of type SPWorkflowActivationProperties which contains all the methods and properties to get the data you need: C#为您创建一个类型为SPWorkflowActivationProperties的workflowProperties变量,其中包含获取所需数据的所有方法和属性:

public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties(); // auto generated code.

Then to get the list item data or even list data all you do is: 然后,要获取列表项数据甚至列出数据,您只需:

SPList oList = workflowProperties.List; // get the list that contains the list item on which the workflow instance is running.
SPListItem oItem = workflowProperties.Item; // get the list item on which the workflow instance is running.

So to get my "Name" data I would've had to: 因此,要获得我的“名称”数据,我将不得不:

string name = workflowProperties.Item["Name"].ToString();

Hope this helps someone, although fortunately nobody is as stupid as me so you guys will probably figure it out yourself. 希望这对某人有所帮助,虽然幸运的是没有人像我一样愚蠢,所以你们可能会自己解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何:使用自定义列表共享点工作流 - How to: sharepoint workflow with custom list Sharepoint 2013,从列表中获取数据到ClientPeoplePicker - Sharepoint 2013, get data from list to ClientPeoplePicker Sharepoint工作流程任务列表标题URL - Sharepoint Workflow Task List Title URL SharePoint沙盒自定义工作流活动可基于多个条件从另一个列表中获取价值 - SharePoint Sandboxed Custom Workflow Activity to get value from another list based on multiple criteria 多个工作流任务陷入Sharepoint 2007 - multiple workflow tasks get stuck in Sharepoint 2007 如何获取SharePoint工作流的事件/触发器? - How to get the event/trigger of a SharePoint workflow? Visual Studio工作流的SharePoint任务列表中的“查找”列 - Lookup column in SharePoint Task List of a Visual Studio Workflow 创建工作流解决方案以发送有关在SharePoint中创建新列表项的电子邮件 - Create a workflow solution to send an email on new list item creation in SharePoint 使用 c# 从外部 SharePoint 在线获取 SharePoint 列表数据 - Get SharePoint list data from outside SharePoint Online using c# Sharepoint工作流:如何在WorkflowItemChanged事件处理程序中获取“ BeforeProperties” - Sharepoint Workflow: How do I get the “BeforeProperties” in a WorkflowItemChanged event handler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM