簡體   English   中英

獲取實例化工作流的SharePoint列表數據?

[英]Get SharePoint list data that instantiated workflow?

因此,我在Visual Studio中創建一個SharePoint 2010項目,該項目包含與某個列表關聯的順序工作流(僅限場解決方案)項,以便在項目添加到列表時工作流啟動。

我的問題是,說一個項目是按以下格式添加的:

名稱| 電子郵件

戴夫| dave@dave.com

有沒有辦法以編程方式將這些數據存儲在變量中? 按原樣,不使用任何硬編碼索引或任何東西,只需以編程方式獲取它,以便我可以提取這些數據並將其存儲在兩個C#變量(int iD,string emailAddress)中,並且工作流知道哪個列表項被踢掉了?

目前我正在這樣做的方式是:

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

但我寧願不使用索引器,因為如果快速添加另一個項目並且列表重新排序然后......災難,索引可能會關閉。

提前致謝!

解決了它們! 非常愚蠢的我忽略了這一點,但這是解決方案:

C#為您創建一個類型為SPWorkflowActivationProperties的workflowProperties變量,其中包含獲取所需數據的所有方法和屬性:

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

然后,要獲取列表項數據甚至列出數據,您只需:

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.

因此,要獲得我的“名稱”數據,我將不得不:

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

希望這對某人有所幫助,雖然幸運的是沒有人像我一樣愚蠢,所以你們可能會自己解決這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM