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