用EventHandler在列表中建立啟動工作流程欄

來源:互聯網
上載者:User
 

一、用EventHandler在列表中建立啟動工作流程欄,先擷取觸發事件的列表,組合啟動的url,其中TemplateId 通過讀相關列表的工作流程(list.WorkflowAssociations)得到,獲得觸發事件的清單項目得到清單項目的ID,將 url賦值給清單項目,更新清單項目。

     public class Meeting : SPItemEventReceiver

    {

         public string startWFString = string.Empty;

        public override void ItemAdded(SPItemEventProperties properties) //重載ItemAdded函數,監控建立列表條目事件

        {

            SPSecurity.RunWithElevatedPrivileges(delegate()      //用此方法類比管理員賬戶運行此事件處理常式

            {

                using (SPSite site = new SPSite(properties.SiteId))    //用此方法的話就不用dispose()了

                {

                    using (SPWeb web = site.OpenWeb(properties.OpenWeb().ID)) //注意獲得web的方法!!!

                    {

                        try

                        {

                            startWFString = web.Url ;

                           if (!startWFString.EndsWith("/"))

                                startWFString = startWFString + "/";

                            startWFString += "_layouts/IniWrkflIP.aspx?List=";

                            SPList list = web.Lists[properties.ListId];     //獲得觸發事件的列表

                            SPWorkflowAssociationCollection wfCollection = list.WorkflowAssociations;

                            //啟動工作流程的列

                            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

                            doc.LoadXml(wfCollection.SoapXml);

                            System.Xml.XmlNode node = doc.SelectSingleNode("WorkflowTemplates/WorkflowTemplate/WorkflowTemplateIdSet/@TemplateId");

                            if (list.EnableMinorVersions)

                            {

                                list.EnableMinorVersions = false;

                            }

                            startWFString += list.ID + "&ID=";

                            SPListItem item = list.Items.GetItemById(properties.ListItemId);    //獲得觸發事件的列表條目

                            startWFString += properties.ListItemId+ "&TemplateID=";

                            startWFString += node.InnerText + "&Source=";

                            string pUrl = web.ParentWeb.Url;

                            string listUrl = list.DefaultViewUrl;

                            startWFString += pUrl + listUrl;

                            item["StartWorkflow"] = startWFString;

                            item["Title"] = item.File.Name;

                            item.Update();

                            string tmp = item["StartWorkflow"].ToString();

                            if (tmp.Contains(","))

                            {

                              string[] arr = tmp.Split(new char[]{','});

                              item["StartWorkflow"] = arr[0] + ", 啟動工作流程";

                              item.Update();

                            }

                            list.EnableMinorVersions = true;

                        }

                        catch (Exception ex)

                        {

                            properties.ErrorMessage = ex.Message;

                        }

                    }

                }

            });

        }

    }

二、 部署EventHandler

利用D:"MOSS"EventHandlerExplorer"EventHandlerExplorer工程部署,點擊EventHandlerExplorer.exe。

U2UCamlCreator.exe可以查詢列表的基本資料。

SPCAMLEditor.exe 修改列表的基本資料。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.