用EventHandler在列表中创建启动工作流栏

 

一、用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 修改列表的基本信息。

转载于:https://www.cnblogs.com/sumh/archive/2008/05/20/1203567.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值