SharePoint 2007:以编程方式启动工作流命中错误
我想在页面库中添加项目时以编程方式启动工作流程。 我执行以下操作:
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem listItem = properties.ListItem;
StartWF(listItem);
}
public void StartWF(SPListItem listItem)
{
using(SPWeb web = listItem.Web) {
using(SPSite site = web.Site) {
SPWorkflowManager manager = site.WorkflowManager;
SPList parentList = listItem.ParentList;
SPWorkflowAssociationCollection associationCollection =
parentList.WorkflowAssociations;
foreach(SPWorkflowAssociation association in
associationCollection) {
if (association.Name == "APWFAnn2010") {
string data =
association.AssociationData;
SPWorkflow wf =
manager.StartWorkflow(listItem,
association,
association.
AssociationData);
}
}
}
}
}
然后我遇到此错误“系统找不到指定的文件。(HRESULT 异常:0x80070002)”
“APWFAnn2010”是我想要启动的工作流程名称。这是在页面库中创建的 SP 默认审批工作流程。
请帮忙,先谢谢你了。
I wanted to programmatically start workflow when itemAdded in Pages Library.
I do as following :
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem listItem = properties.ListItem;
StartWF(listItem);
}
public void StartWF(SPListItem listItem)
{
using(SPWeb web = listItem.Web) {
using(SPSite site = web.Site) {
SPWorkflowManager manager = site.WorkflowManager;
SPList parentList = listItem.ParentList;
SPWorkflowAssociationCollection associationCollection =
parentList.WorkflowAssociations;
foreach(SPWorkflowAssociation association in
associationCollection) {
if (association.Name == "APWFAnn2010") {
string data =
association.AssociationData;
SPWorkflow wf =
manager.StartWorkflow(listItem,
association,
association.
AssociationData);
}
}
}
}
}
then I hit this error "The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"
"APWFAnn2010" is the workflow name I wanted to start. It is SP default Approval Workflow created in Pages Library.
Please help, thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以通过这种方式将名称传递到上面的函数中,然后您将拥有一个可以在任何项目上启动任何工作流程的函数:
You can also pass in the name into the function above by doing it this way, and then you'd have a function that can start any workflow on any item:
首先,您在
using web
中拥有您的using site
,这应该是相反的 - 另一方面,我什至没有看到您使用 SPWeb,所以为什么里面有吗?其次,我会稍微重写一下代码:First of you have your
using site
within theusing web
it should be the other way around - on the other hand I don't even see you using the SPWeb, so why have it in there?. And secondly I would rewrite the code a bit: