如何使用c#以编程方式启动Sharepoint Approval工作流? [英] How to start Sharepoint Approval Workflow programatically using c#?

查看:148
本文介绍了如何使用c#以编程方式启动Sharepoint Approval工作流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I want to start an approval workflow on the click of a button. I need to set all the parameters of the workflow, and its approver, everything programatically. Can anyone help me with this please?

I am very new to SharePoint and do not have SharePoint installed on my computer. I have access to a SharePoint site and I'm trying to learn SP through it.

推荐答案

你可以要么使用服务器端对象模型,只允许在安装了Sharepoint的同一台服务器上运行应用程序,要么在任何地方运行客户端对象模型。



JavaScript,SilverLight,Mobile和Managed使用的客户端对象模型有不同版本。从C#客户端应用程序,您可能需要托管版本。这些程序集可以在Sharepoint安装的ISAPI文件夹中找到,并可以复制到Visual Studio环境中以供参考。



使用对象模型,你将会去访问附加了批准工作流程的正确列表,找到附加的工作流程,然后启动它。



我没有完整的代码示例,但是它应该给你一个想法:

You can either use the Server-side object model, allowing you to run the application only on the same server that has Sharepoint installed, or the client object model, which you can run from anywhere.

There are different version of the client object model for JavaScript, SilverLight, Mobile and Managed use. From a C# client application, you'll probably need the Managed version. Those assemblies can be found in the ISAPI folder of your Sharepoint installation, and can be copied to your Visual Studio environment to reference.

Using the Object Model, you are going to access the correct list that has the approval workflow attached to it, find the attached workflow, and start it.

I don't have a complete code sample, but it should give you an idea:
ClientContext context = new ClientContext("http://SiteUrl"); 

// The SharePoint web at the URL.
Web web = context.Web; 

// The list with the WF attached
List list = web.Lists.GetByTitle("My List");

var workflowManager = context.Current.Site.WorkflowManager; // untested
var workflowAssociations = list.WorkflowAssociations; // untested



我不知道这里有一个包含所有SP引用的工作环境,因此最后两行未经测试。

此外,您需要在WorkflowAssocations列表中找到批准工作流程(通过GUID或名称,我是不确定?抱歉,没有代码示例。

然后使用WorkflowManager使用正确的AssociationData启动工作流程(抱歉,没有代码示例)


I don't have a working environment with all the SP references here, so the last two lines are untested.
Also, you need to find the approval workflow in the list of WorkflowAssocations (by GUID or name, I'm not sure? sorry, no code sample).
Then use the WorkflowManager to start the Workflow with the right AssociationData (sorry, no code sample)


这篇关于如何使用c#以编程方式启动Sharepoint Approval工作流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆