设为首页 收藏本站
查看: 928|回复: 0

[经验分享] SharePoint State Machine Workflow +ASP.NET ASPX Form step by step(2)-创建Associati

[复制链接]

尚未签到

发表于 2015-9-27 14:08:49 | 显示全部楼层 |阅读模式
  在workflow中,有四种表单,分别是Association,Instantiation,Modification,TaskEdit.这篇我就讲讲如何自定义一个Association表单。
  但什么是Association表单?当我们为一个Library、list加上一个workflow的时候,会出现下图,当我们点击Next之后,如果我们自定义了一个Association表单的话,那么你就会跳转到相应的你自己定义的那个表单页面。而总的来说,这个页面是对你的这个workflow做一些定义,你可以为这个workflow加上一些缺省的值,这些值是List/Library级别的,在每个不同Item的workflow中都可以使用。例如,我们可以在Association表单中定义缺省的审批人,然后在后面的Instantiation表单中显现(前提是你有自定义这个表单),在这个表单中你可以直接就使用Association表单中已经定义的审批者,也可以对他们进行修改。从我的理解来说,Association表单就是让你能够在List/Library级别上做些缺省设置,然后在接下来的步骤中,你可以选择使用这些,也可以进行修改用你自己的定义的值。
  
DSC0000.jpg      
  首先,我们要定义一个APSX页面。我的做法是先创建一个Class Library的工程,把原先的文件删了,自己创建一个ASPX文件,和一个CLass Library作为aspx文件的后台代码。
  
  
DSC0001.jpg      
  你可以先将这个工程编译一下,生成一个dll,那么你就可以将这个Assmebly加到你的aspx文件头中。然后加上一些指令,你可以到layouts文件下找一个application页面,将一些公用的指令代码贴过来就行了。这些部分都是公用的,除最开头的Assembly和Inherits是不同的,其它的都可以用的。
  

<%@ Assembly Name="MyASPXPage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=91dbd359a1533843" %>
<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" EnableSessionState="true" ValidateRequest="False" AutoEventWireup="true" Inherits="MyASPXPage.MyAss" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>   
<%@ Register TagPrefix="wssuc" TagName="LinksTable" src="/_controltemplates/LinksTable.ascx" %> <%@ Register TagPrefix="wssuc" TagName="InputFormSection" src="/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormControl" src="/_controltemplates/InputFormControl.ascx" %> <%@ Register TagPrefix="wssuc" TagName="LinkSection" src="/_controltemplates/LinkSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ButtonSection" src="/_controltemplates/ButtonSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ActionBar" src="/_controltemplates/ActionBar.ascx" %> <%@ Register TagPrefix="wssuc" TagName="ToolBar" src="/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="/_controltemplates/ToolBarButton.ascx" %> <%@ Register TagPrefix="wssuc" TagName="Welcome" src="/_controltemplates/Welcome.ascx" %>
<%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Workflow" Namespace="Microsoft.SharePoint.Workflow" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  
  在master页面中有很多的PlaceHolder,但对于我们来说只有PlaceHolderMain是最重要的,我们的控件都是放在这里,你要是对其它的PlaceHolder感兴趣,你可以自己加上相应的东西。
  

DSC0002.gif DSC0003.gif Code
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">   
     
        <wssuc:InputFormSection Title="Default Workflow Start Values" Description="My Association Form"
            runat="server">
            <template_inputformcontrols>
                <wssuc:InputFormControl LabelText="Reviewers:" runat="server">
                    <Template_Control>
                        <wssawc:PeopleEditor
                                    AllowEmpty="true"
                                    ValidatorEnabled="true"
                                    id="Reviewers"
                                    runat="server"
                                    SelectionSet="User,SecGroup,SPGroup"
                                    width='300px' MultiSelect="true"/>
                        </Template_Control>
                </wssuc:InputFormControl>
                <wssuc:InputFormControl LabelText="Type a message to include with your request:" runat="server">
                        <Template_Control>
                            <wssawc:InputFormTextBox Title="Task Description" class="ms-input" ID="Description" runat="server" TextMode="MultiLine" Columns="40" Rows="5"/>
                        </Template_Control>
                </wssuc:InputFormControl>
            </template_inputformcontrols>
        </wssuc:InputFormSection>
        <wssuc:ButtonSection runat="server">
            <template_buttons>
            <asp:PlaceHolder runat="server">
               
                <asp:Button runat="server" class="ms-ButtonHeightWidth" OnClick="btnOK_Click" Text="OK" id="btnOK"/>
            </asp:PlaceHolder>
        </template_buttons>
        </wssuc:ButtonSection>
               
        <input type="hidden" name="WorkflowDefinition" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["WorkflowDefinition"]),Response.Output); %>' />
        <input type="hidden" name="WorkflowName" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["WorkflowName"]),Response.Output); %>'/>
        <input type="hidden" name="AddToStatusMenu" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AddToStatusMenu"]),Response.Output); %>'/>
        <input type="hidden" name="AllowManual" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AllowManual"]),Response.Output); %>'/>
        <input type="hidden" name="RoleSelect" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["RoleSelect"]),Response.Output); %>'/>
        <input type="hidden" name="GuidAssoc" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["GuidAssoc"]),Response.Output); %>'/>
        <input type="hidden" name="SetDefault" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["SetDefault"]),Response.Output); %>'/>
        <input type="hidden" name="HistoryList" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["HistoryList"]),Response.Output); %>'/>
        <input type="hidden" name="TaskList" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["TaskList"]),Response.Output); %>'/>
        <input type="hidden" name="UpdateLists" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["UpdateLists"]),Response.Output); %>' />      
        <input type="hidden" name="AutoStartCreate" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AutoStartCreate"]),Response.Output); %>' />
        <input type="hidden" name="AutoStartChange" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AutoStartChange"]),Response.Output); %>' />

</asp:Content>  
  以上就是ASPX文件的所有内容,后面我们就要着手我们的后台代码了。首先我们要定义一大堆的变量,这些变量是用来保存例如ListId,ItemId,WorkflowId,TaskList等等之类的东西。你还要定义相应的控件,变量名要和你aspx文件控件id一样。
  

Code
DSC0004.gif private SPWeb _myTeamSite;              

        Paramater variables received from the Workflow Attachment screen#region Paramater variables received from the Workflow Attachment screen
DSC0005.gif
        string _paramWorkflowName = string.Empty;               
        string _paramWorkflowGuid = string.Empty;               
        string _paramSPListGuid = string.Empty;                 
        string _paramTaskList = string.Empty;                  
        string _paramHistoryList = string.Empty;                     
        bool _paramAutoStartWF_OnItemChange;                    
        bool _paramAllowManualStart;                           
        string _paramWorkflowAssociationGuid = string.Empty;   

DSC0006.gif         #endregion

        Workflow List, Template and Association Variables#region Workflow List, Template and Association Variables

        bool _worfkflowAssociationExists = false;           
        SPList _sharePointListAttachedTo;                  
        Guid _workflowAssociationGuid;                     
        SPWorkflowAssociation _workflowAssociationObject;   
        Guid _workflowTemplateGuid;                        
        SPWorkflowTemplate _workflowTemplateObject;         
        #endregion

        Task List and History List variables#region Task List and History List variables

        SPList _workflowtTaskList;                          
        SPList _workflowHistoryList;                        
        #endregion  你先是重载OnPreInit函数。
  
  protected override void OnPreInit(EventArgs e)
        {
          this._myTeamSite = SPControl.GetContextWeb(Context);
         }
  然后为前先无数的变量设置值。因为我们自定义Association Form,原先我们点击了Next之后,相应的workflow就与相应的List联系起来,现在,这些工作要我们自己来做。代码就不贴了,看附件吧(其实代码借用了很多前人的代码)。大家一看就能明白了。下面也没有什么需要嘱咐的地方,就有个地方,在我们的Association Form上有个按钮,你不需要对控件加上一个EventHandler,你只需要在代码中实现一个和页面控件OnClick属性值同名的一个函数,函数原型就和一般的EventHandler是一样的,但记得要设为Public。
  将生成的dll放到GAC中。(要强签名),把ASPX文件放到layouts文件夹下,在你生成的workflow的workflow.xml中做加上 AssociationUrl="_layouts/MyAss.aspx"
  

Code
<Workflow
     Name="TestWorkflow"
     Description="My SharePoint Workflow"
     Id="e0d38698-f244-492a-ae32-4ca3ebcb1b03"
     CodeBesideClass="TestWorkflow.Workflow1"
     CodeBesideAssembly="TestWorkflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd996aa41f54bf80"
     AssociationUrl="_layouts/MyAss.aspx" />  
  我的页面的样子
  
DSC0007.jpg      希望大家对提意见。
  Association Form
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-119560-1-1.html 上篇帖子: 《Microsoft Office SharePoint Server 2007 前瞻技术指南》第八章预览_Excel Services 下篇帖子: Sharepoint学习笔记—error处理--一个部署报错:deployment or retraction is already under way
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表