SPD工作流的部署

     现在我有一个网站,开发后另存为模板。该网站有SPD设计的工作流。

     大家都知道,SPD工作的部署是很麻烦的。我参考了http://blog.joycode.com/ipark/archive/2008/01/16/113795.aspx的文章,讲解的很详细。楼主最后是这么说的:

从原理上来说这样做是行得通的,当然我并没有试过:)。

    我在项目中有个小的模块需要解决这样的问题。最后经过各种调试得出下面的经验,特来分享。

    1.把你的网站设计好,工作流设计好以后,最好把你的列表的spd工作流的以前版本删除。

  从SPD中打开你的网站,找到后缀.xmol.wfConfig.xml的文件。具体的架构如下

 WorkflowConfig>
    <Template
        BaseID="{21DF3370-0024-4135-ABF0-AD30C524DBB5}"
        DocLibID="{295C048C-3EBE-4ECC-A2D5-008AC6755F26}"
        XomlHref="Workflows/会议申请工作流/会议申请工作流.xoml"
        XomlVersion="V3.0"
        RulesHref="Workflows/会议申请工作流/会议申请工作流.xoml.rules"
        RulesVersion="V3.0"
    >
    </Template>
    <Association
        ListID="{6C7DE962-534C-4C35-896F-AE631A4793F2}"
        TaskListID="{2399D43F-4488-46A0-9367-E90CB91A8CE6}"
        StartOnCreate="true"
        StartOnChange="true"
    >
    </Association>
    <ContentTypes>
        <ContentType Name="部门领带审批" ContentTypeID="0x01080100DD32E2262C9D844D8C8AAB32DB6E4A8E0063AD1201DB68274FADE16DA7695BEC60" Form="/Workflows/会议申请工作流/部门领带审批.aspx" Description=""><Fields><Field Format="RadioButtons" BaseType="Text" Required="TRUE" DisplayName="领导审批选项" Description="" Direction="None" Type="Choice" ID="{352c3660-959b-4f6b-b20d-ce2c63b167a3}" SourceID="{1c29331f-2366-40fa-96da-e71453795186}" StaticName="审批选项" Name="_x5ba1__x6279__x9009__x9879_" Hidden="FALSE" Customization="" ReadOnly="FALSE" PITarget="" PrimaryPITarget="" PIAttribute="" PrimaryPIAttribute="" Aggregation="" Node="" ColName="nvarchar13" RowOrdinal="0" Version="2"><Default>拒绝</Default><CHOICES><CHOICE>拒绝</CHOICE><CHOICE>同意</CHOICE></CHOICES></Field><Field NumLines="5" Sortable="FALSE" RichTextMode="Compatible" DisplayName="领导详细意见" Description="" Direction="None" Type="Note" ID="{b57f1471-b129-429a-87e3-637be7a40dad}" SourceID="{1c29331f-2366-40fa-96da-e71453795186}" StaticName="领导意见1" Name="_x9886__x5bfc__x610f__x89c1_1" Required="FALSE" Hidden="FALSE" Customization="" ReadOnly="FALSE" PITarget="" PrimaryPITarget="" PIAttribute="" PrimaryPIAttribute="" Aggregation="" Node="" ColName="ntext7" RowOrdinal="0" Version="2"/></Fields></ContentType>
    </ContentTypes>
    <Initiation URL="Workflows/会议申请工作流/会议申请工作流.aspx">
        <Fields/>
        <Parameters></Parameters>
    </Initiation>
</WorkflowConfig>

把RulesVersion="V3.0"改成"V1.0",如过你需要部署的网站地址如:http://dmtmossdev:2010/sites/ModeSite/Pages/Default.aspx

包括sites/ 这路径要注意了。

2.把你的网站另存为模板.stp文件

3.把.stp文件上传到你需要部署的网站

3.使用feature激活网站和网站的事件

 

 

  using (SPSite site = new SPSite(((SPSite)properties.Feature.Parent).Url))
                {
                    //创建网站
                    SPWebTemplateCollection templates = site.GetCustomWebTemplates(2052);
                    SPWebTemplate template = templates["MeetingManager.stp"];
                    if (template != null)
                    {
                        try
                        {
                            web = site.AllWebs["MeetingManager"];
                            web.Delete();
                        }
                        catch (Exception ex)
                        {

                        }

                        web = site.AllWebs.Add("MeetingManager", "会议管理", "会议管理网站", 2052, template, false, false);
                        web.Update();
                    }
                    if (web != null)
                    {
                        SPList listMeetingApply = web.Lists["会议申请"];//会议申请list
                        SPList listMeetingCar = web.Lists["会议车辆"];//会议车辆的list
                        SPList listMeetingRoom = web.Lists["会议室"];//会议室的list
                        SPList listMeetingLog = web.Lists["会议决议"]会议决议的list
                        SPList listTask = web.Lists["任务"];//任务的list
                        SPList listMeetingEquipment = web.Lists["会议设备"];//会议设备的list

                        SPList ListWorkFlow = web.Lists["工作流"];//工作流的list

                        StreamReader reader = null;
                        string strXOML = string.Empty;
                        string strRules = string.Empty;
                        string strConfig = string.Empty;
                        string strVersion = string.Empty;
                        string strConfigPath = string.Empty;
                        foreach (SPListItem item in ListWorkFlow.Folders)
                        {
                            SPFolder folder = item.Folder;
                            if (folder.Name.Equals("会议申请工作流")) //你工作流的名字
                            {
                                foreach (SPFile file in folder.Files)
                                {

                                    if (file.Name.EndsWith("xoml"))
                                    {
                                        file.CheckOut(false, string.Empty);
                                        reader = new System.IO.StreamReader(file.OpenBinaryStream());
                                        strXOML = reader.ReadToEnd();
                                        reader.Dispose();
                                        file.Update();
                                        file.CheckIn(string.Empty);
                                        continue;
                                    }
                                    if (file.Name.EndsWith("rules"))
                                    {
                                        file.CheckOut(false, string.Empty);
                                        reader = new System.IO.StreamReader(file.OpenBinaryStream());
                                        strRules = reader.ReadToEnd();
                                        reader.Dispose();
                                        file.Update();
                                        file.CheckIn(string.Empty);
                                        continue;
                                    }
                                    if (file.Name.EndsWith(".xml"))
                                    {
                                        file.CheckOut(false, string.Empty);
                                        reader = new System.IO.StreamReader(file.OpenBinaryStream());
                                        strConfig = reader.ReadToEnd();
                                        reader.Dispose();

                                        strConfigPath = file.ServerRelativeUrl.Substring(file.ServerRelativeUrl.IndexOf(web.Name) + web.Name.Length + 1);

                                        XmlDocument xdot = new XmlDocument();
                                        xdot.Load(file.OpenBinaryStream());

                                        XPathNavigator xpRot = xdot.CreateNavigator();
                                        XPathNavigator xpDocLibID = xpRot.SelectSingleNode("WorkflowConfig/Template/@DocLibID");
                                        XPathNavigator xpListID = xpRot.SelectSingleNode("WorkflowConfig/Association/@ListID");
                                        XPathNavigator xpTaskListID = xpRot.SelectSingleNode("WorkflowConfig/Association/@TaskListID");
                                        XPathNavigator xpInitiationURL = xpRot.SelectSingleNode("WorkflowConfig/Initiation/@URL");
                                        XPathNavigator xpForm = xpRot.SelectSingleNode("WorkflowConfig/ContentTypes/ContentType/@Form");

                                        xpDocLibID.SetValue("{" + ListWorkFlow.ID.ToString() + "}");  //工作流列表的ID
                                        xpListID.SetValue("{" + listMeetingApply.ID.ToString() + "}");//你绑定的列表的id
                                        xpTaskListID.SetValue("{" + listTask.ID.ToString() + "}");//任务列表的ID

                                        //xpInitiationURL.SetValue(web.ServerRelativeUrl + "/" + xpInitiationURL.Value);

                                        if (web.ServerRelativeUrl.ToLower().Contains("sites/"))  //如果带sites/的话是和不带是不一样的
                                        {
                                            xpForm.SetValue(web.Name + xpForm.Value);
                                        }

                                        strConfig = xdot.OuterXml;
                                        file.SaveBinary(System.Text.Encoding.UTF8.GetBytes(strConfig));

                                        file.Update();
                                        file.CheckIn(string.Empty);
                                        continue;
                                    }
                                }
                            }

                            break;
                        }
                        Microsoft.SharePoint.SoapServer.WebPartPagesWebService objWebPartPages = new Microsoft.SharePoint.SoapServer.WebPartPagesWebService(web);
                        string strResult;
                        strResult = objWebPartPages.ValidateWorkflowMarkupAndCreateSupportObjects(strXOML, strRules, strConfig, "2");

                        //associate with list
                        string param1 = strConfigPath;
                        string param2 = strVersion;
                        strResult = objWebPartPages.AssociateWorkflowMarkup(param1, param2);
                        web.Update();

                        SPNavigation navi = web.Navigation;
                        SPNavigationNodeCollection naviCol = navi.QuickLaunch;
                        foreach (SPNavigationNode naviNode in naviCol)
                        {
                            if (naviNode.Title.Equals("会议申请"))
                            {
                                for (int i = 0; i < naviNode.Children.Count; i++)
                                {
                                    SPNavigationNode childrenNode = naviNode.Children[i];
                                    if (childrenNode.Title.Equals("新建会议申请"))
                                    {
                                        childrenNode.Url = listMeetingApply.RootFolder.ServerRelativeUrl + "/NewForm.aspx";
                                        childrenNode.Update();
                                        continue;
                                    }
                                    if (childrenNode.Title.Equals("查看会议申请"))
                                    {
                                        childrenNode.Url = listMeetingApply.RootFolder.ServerRelativeUrl;
                                        childrenNode.Update();
                                        continue;
                                    }
                                }
                                naviNode.Update();
                                continue;
                            }

                            if (naviNode.Title.Equals("会议决议"))
                            {
                                for (int i = 0; i < naviNode.Children.Count; i++)
                                {
                                    SPNavigationNode childrenNode = naviNode.Children[i];
                                    if (childrenNode.Title.Equals("新建会议决议"))
                                    {
                                        childrenNode.Url = listMeetingLog.RootFolder.ServerRelativeUrl + "/NewForm.aspx";
                                        childrenNode.Update();
                                        continue;
                                    }
                                    if (childrenNode.Title.Equals("查看会议决议"))
                                    {
                                        childrenNode.Url = listMeetingLog.RootFolder.ServerRelativeUrl;
                                        childrenNode.Update();
                                        continue;
                                    }
                                }
                                naviNode.Update();
                                continue;
                            }
                            if (naviNode.Title.Equals("查看车辆"))
                            {
                                naviNode.Url = listMeetingCar.RootFolder.ServerRelativeUrl;
                                naviNode.Update();
                                continue;
                            }
                            if (naviNode.Title.Equals("查看会议室"))
                            {
                                naviNode.Url = listMeetingRoom.RootFolder.ServerRelativeUrl;
                                naviNode.Update();
                                continue;
                            }
                            if (naviNode.Title.Equals("查看会议设备"))
                            {
                                naviNode.Url = listMeetingEquipment.RootFolder.ServerRelativeUrl;
                                naviNode.Update();
                                continue;
                            }

                            if (naviNode.Title.Equals("所有任务"))
                            {
                                for (int i = 0; i < naviNode.Children.Count; i++)
                                {
                                    SPNavigationNode childrenNode = naviNode.Children[i];
                                    if (childrenNode.Title.Equals("未完成任务"))
                                    {
                                        childrenNode.Url = listTask.Views["未完成任务"].ServerRelativeUrl;
                                        childrenNode.Update();
                                        continue;
                                    }
                                    if (childrenNode.Title.Equals("已完成任务"))
                                    {
                                        childrenNode.Url = listTask.Views["已完成任务"].ServerRelativeUrl;
                                        childrenNode.Update();
                                        continue;
                                    }
                                }
                                naviNode.Update();
                                continue;
                            }
                        }


                        for (int i = listMeetingApply.EventReceivers.Count; 0 < i; i--)
                        {
                            SPEventReceiverDefinition receiver = listMeetingApply.EventReceivers[i - 1];
                            if (receiver.Class.Equals(EventHandlerNameSpace + MeetingApply_EventHandlerClass))
                            {
                                receiver.Delete();
                            }
                        }
                        for (int i = listMeetingCar.EventReceivers.Count; 0 < i; i--)
                        {
                            SPEventReceiverDefinition receiver = listMeetingCar.EventReceivers[i - 1];
                            if (receiver.Class.Equals(EventHandlerNameSpace + MeetingCar_EventHandlerClass))
                            {
                                receiver.Delete();
                            }
                        }
                        for (int i = listMeetingRoom.EventReceivers.Count; 0 < i; i--)
                        {
                            SPEventReceiverDefinition receiver = listMeetingRoom.EventReceivers[i - 1];
                            if (receiver.Class.Equals(EventHandlerNameSpace + MeetingRoom_EventHandlerClass))
                            {
                                receiver.Delete();
                            }
                        }
                        for (int i = listMeetingLog.EventReceivers.Count; 0 < i; i--)
                        {
                            SPEventReceiverDefinition receiver = listMeetingLog.EventReceivers[i - 1];
                            if (receiver.Class.Equals(EventHandlerNameSpace + MeetingLog_EventHandlerClass))
                            {
                                receiver.Delete();
                            }
                        }

                        listMeetingApply.EventReceivers.Add(SPEventReceiverType.ItemAdding, assembleName, EventHandlerNameSpace + MeetingApply_EventHandlerClass);
                        listMeetingApply.EventReceivers.Add(SPEventReceiverType.ItemAdded, assembleName, EventHandlerNameSpace + MeetingApply_EventHandlerClass);
                        listMeetingApply.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assembleName, EventHandlerNameSpace + MeetingApply_EventHandlerClass);
                        listMeetingApply.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assembleName, EventHandlerNameSpace + MeetingApply_EventHandlerClass);
                        listMeetingApply.EventReceivers.Add(SPEventReceiverType.ItemDeleting, assembleName, EventHandlerNameSpace + MeetingApply_EventHandlerClass);
                        listMeetingApply.EventReceivers.Add(SPEventReceiverType.ItemDeleted, assembleName, EventHandlerNameSpace + MeetingApply_EventHandlerClass);

                        listMeetingCar.EventReceivers.Add(SPEventReceiverType.ItemAdding, assembleName, EventHandlerNameSpace + MeetingCar_EventHandlerClass);
                        listMeetingCar.EventReceivers.Add(SPEventReceiverType.ItemAdded, assembleName, EventHandlerNameSpace + MeetingCar_EventHandlerClass);
                        listMeetingCar.EventReceivers.Add(SPEventReceiverType.ItemDeleting, assembleName, EventHandlerNameSpace + MeetingCar_EventHandlerClass);
                        listMeetingCar.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assembleName, EventHandlerNameSpace + MeetingCar_EventHandlerClass);

                        listMeetingRoom.EventReceivers.Add(SPEventReceiverType.ItemAdding, assembleName, EventHandlerNameSpace + MeetingRoom_EventHandlerClass);
                        listMeetingRoom.EventReceivers.Add(SPEventReceiverType.ItemAdded, assembleName, EventHandlerNameSpace + MeetingRoom_EventHandlerClass);
                        listMeetingRoom.EventReceivers.Add(SPEventReceiverType.ItemDeleting, assembleName, EventHandlerNameSpace + MeetingRoom_EventHandlerClass);
                        listMeetingRoom.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assembleName, EventHandlerNameSpace + MeetingRoom_EventHandlerClass);

                        listMeetingLog.EventReceivers.Add(SPEventReceiverType.ItemAdded, assembleName, EventHandlerNameSpace + MeetingLog_EventHandlerClass);
                        listMeetingLog.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assembleName, EventHandlerNameSpace + MeetingLog_EventHandlerClass);
                        listMeetingLog.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assembleName, EventHandlerNameSpace + MeetingLog_EventHandlerClass);

                        //删除MeetingTimerJob
                        foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                        {
                            if (job.Name.Equals(jobName))
                            {
                                job.Delete();
                            }
                        }

                        MeetingTimerJob meetingTimerJob = new MeetingTimerJob(jobName, site.WebApplication);

                        //SPHourlySchedule schedule = new SPHourlySchedule();                  
                        //schedule.BeginMinute = 40;
                        //schedule.EndMinute = 45;

                        SPMinuteSchedule schedule = new SPMinuteSchedule();
                        schedule.BeginSecond = 0;
                        schedule.EndSecond = 59;
                        schedule.Interval = 1;
                        meetingTimerJob.Schedule = schedule;
                        meetingTimerJob.Update();
                    }
                }
            }
            catch (Exception ex)
            {
                //异常处理

            }
            finally
            {
                if (web != null)
                {
                    web.Dispose();
                }
            }

 

 通过了测试的,是可以用的。如需要源码科与本人联系。乐意和一切热爱MOSS的所有人交流。

  email:[email protected]

           [email protected]

 

.

你可能感兴趣的:(工作流)