sharepoint 下Infopath 表单启动工作流
using Microsoft.Office.InfoPath; using System; using System.Xml; using System.Xml.XPath; using Microsoft.SharePoint; using Microsoft.SharePoint.Workflow; using System.Web; namespace 表单109 { public partial class FormCode { // 启用浏览器功能的表单不支持成员变量。 // 请使用代码从 FormState 词典 // 写入和读取这些值,如下所示: // // private object _memberVariable // { // get // { // return FormState["_memberVariable"]; // } // set // { // FormState["_memberVariable"] = value; // } // } // 注意: 以下是 Microsoft InfoPath 所需的过程。 // 可以使用 Microsoft InfoPath 对其进行修改。 public void InternalStartup() { ((ButtonEvent)EventManager.ControlEvents["btnsubmit"]).Clicked += new ClickedEventHandler(btnsubmit_Clicked); ((ButtonEvent)EventManager.ControlEvents["btnsave"]).Clicked += new ClickedEventHandler(btnsave_Clicked); ((ButtonEvent)EventManager.ControlEvents["btnclose"]).Clicked += new ClickedEventHandler(btnclose_Clicked); EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading); } public void btnsubmit_Clicked(object sender, ClickedEventArgs e) { // 在此处编写代码。 // 在此处编写代码。 // XPathNavigator field2 = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:标题", NamespaceManager); FileSubmitConnection osssubmit = (FileSubmitConnection)this.DataConnections["OSSSubmit"]; string tempfilename = DateTime.Now.ToString("yyyyMMddHHmmss"); //设置提交表单的文件名 osssubmit.Filename.SetStringValue(tempfilename + ".xml"); //执行提交 osssubmit.Execute(); try { using (SPSite mysite = new SPSite(osssubmit.FolderUrl)) { string workflowName = "TestInfoPath"; string fileurl = osssubmit.FolderUrl + "/" + tempfilename + ".xml"; if (osssubmit.FolderUrl.EndsWith("/")) { fileurl = osssubmit.FolderUrl + tempfilename + ".xml"; } SPList mylist = mysite.RootWeb.GetList(osssubmit.FolderUrl); SPListItem mylistitem = mysite.RootWeb.GetListItem(fileurl); SPWorkflowAssociation mywfass = mylist.WorkflowAssociations.GetAssociationByName(workflowName, System.Globalization.CultureInfo.CurrentCulture); string EventData = mywfass.AssociationData; mysite.AllowUnsafeUpdates = true; mysite.RootWeb.AllowUnsafeUpdates = true; //根据设定的信息,启动工作流 mysite.WorkflowManager.StartWorkflow(mylistitem, mywfass, EventData); // SPUtility.Redirect(osssubmit.FolderUrl, SPRedirectFlags.DoNotEndResponse, HttpContext.Current); } } catch (Exception ex) { } } public void btnsave_Clicked(object sender, ClickedEventArgs e) { // 在此处编写代码。 FileSubmitConnection osssubmit = (FileSubmitConnection)this.DataConnections["OSSSubmit"]; string tempfilename = DateTime.Now.ToString("yyyyMMddHHmmss"); //设置提交表单的文件名 osssubmit.Filename.SetStringValue(tempfilename + ".xml"); //执行提交 osssubmit.Execute(); } public void btnclose_Clicked(object sender, ClickedEventArgs e) { // 在此处编写代码。 } public void loadinfo() { FileSubmitConnection osssubmit = (FileSubmitConnection)this.DataConnections["OSSSubmit"]; using (SPSite mysite = new SPSite(osssubmit.FolderUrl)) { XPathNavigator field2 = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:填写人", NamespaceManager); string username = mysite.RootWeb.CurrentUser.LoginName; field2.SetValue(username); } } public void FormEvents_Loading(object sender, LoadingEventArgs e) { // 在此处编写代码。 loadinfo(); } } }