我以前见过这个错误,不幸的是它是不可预测的,我可以给你的是一个对我有用的解决方法,它涉及为你要求 SharePoint 创建的任务指定 listItemID(而不是 GUID),你可以从那里访问假设创建成功,则在任何未来事件上列出项目。如果您使用的列表获得大量流量,这可能由于竞争条件而无法工作......
再次“解决方法”,所以要小心... - 当您创建任务“onTaskCreateTask1”时,在 SPWorkflowTaskProperties.TaskItemID = x 中明确指定 taskItemID,其中 x 是您生成的值。
- 将生成的 taskItemID 存储在成员变量中 - 使用 getListItemFromID(x) 方法或使用 list.items[x] 方法/访问器访问列表
我没有写下面的代码,感谢 Martin Holy .. http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/26ff3ce1-6d6f-40a5-90b4-a7436acdfffe
/// <summary>
/// Because our task form's don't let us inject the ID we have to
/// generate one beforehand.
/// </summary>
/// <param name="site"></param>
/// <param name="listId"></param>
/// <returns></returns>
public static int GetNextAvailableIdFromList(SPSite site, Guid listId)
{
int nextAvailableID = -1;
if (site.WebApplication.ContentDatabases.Count > 0)
{
string DBConnString = site.WebApplication.ContentDatabases[0].DatabaseConnectionString;
SqlConnection con = new SqlConnection(DBConnString);
try
{
con.Open();
SqlCommand com = con.CreateCommand();
com.CommandText = String.Format("select tp_NextAvailableId from AllLists where tp_ID = '{0}'", listId.ToString());
nextAvailableID = (int)com.ExecuteScalar();
}
finally
{
con.Close();
}
}
return nextAvailableID;
}