[英]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.