The completed workflow task is a basic approval process.
In the past, when developing SharePoint on vs2008, it was troublesome to use the custom association form or initialization form on the ASPX page, you need to manually add the master in SP and other things according to its page, and also need to obtain the form data of the previous page, and manually create form data to pass to the next page. After vs2010, everything became simple. Now it can automatically generate associated form templates and initialize form templates without worrying about style and data transmission issues. (For example)
Next we open vs2010 and select the SharePoint Project template to create a project for the sequential workflow;
Select form soluation for deployment, select list workflow, and associate the list you used during debugging with the next button.
Right-click the project list and add a ing folder to the layouts directory, this is because only the folder can be added under it to add new items will have associated form or initialization form template selection.
Create Association form
Here, we will briefly describe what is an association form. In my understanding, we will fill in some default data that will be automatically filled in during WF initialization when associating WF with list or document. Of course, some other operations are also performed on the associated form page, such as creating a list and WF associated information storage, creating a task list and history list.
Right-click the "layouts" directory and click "Add new item" to add the "Join form" option to the SharePoint Project template.
In this way, the associated form is created. Let's see what it has done for us. First, we have introduced the required spProgramSet and associate the master page in the site. The main modification is inside the content control with the ID of placeholdermain.
During the design interface, I also registered two other SP controls, inputformsection and inputformcontrol (because some SP controls have. the ascx file needs to be registered by yourself when you use it, and some do not need to be registered if you use classes directly .)
<% @ Register tagprefix = "wssuc" tagname = "inputformsection" src = "/_ controltemplates/inputformsection. ascx "%> <% @ register tagprefix =" wssuc "tagname =" inputformcontrol "src ="/_ controltemplates/inputformcontrol. ascx "%>
Let's take a look at the overall effect:
Front-endCodeThe code in placeholdermain is as follows)
<Asp: content ID = "Main" contentplaceholderid = "placeholdermain" runat = "server"> <Table border = "0" cellspacing = "0" cellpadding = "0" class = "MS-propertysheet "width =" 100% "> <colgroup> <Col style =" width: 60% "/> <Col style =" width: 40% "/> </colgroup> <tr> <TD> <wssuc: inputformsection id = "inputformsection1" runat = "server" Title = "select a specified person to approve" Description = "this is an example of associationform. "> <template_inputformcontrols> <wssuc: inputformcontrol runat =" server "labeltext =" people: "labelassociatedcontrolid =" sp_peoleeditor "> <template_control> <SharePoint: peopleeditor runat = "server" id = "sp_peoleeditor"/> </template_control> </wssuc: inputformcontrol> </template_inputformcontrols> </wssuc: inputformsection> </TD> </tr> <TD> <wssuc: inputformsection id = "inputformsection3" runat = "server" Title = "Request Information" Description = "this is an example of associationform. "> <template_inputformcontrols> <wssuc: inputformcontrol runat =" server "labelassociatedcontrolid =" textbox1 "> <template_control> <asp: textbox id = "textbox1" runat = "server" textmode = "multiline" rows = "5"> </ASP: textbox> </template_control> </wssuc: inputformcontrol> </template_inputformcontrols> </wssuc: inputformsection> </TD> </tr> <TD> <wssuc: inputformsection id = "inputformsection2" runat = "server" Title = "Confirm Association" Description = "this is an example of associationform. "> <template_inputformcontrols> <wssuc: inputformcontrol runat =" server "labelassociatedcontrolid =" Panel1 "> <template_control> <asp: panel id = "Panel1" runat = "server"> <asp: button id = "associateworkflow" runat = "server" onclick = "associateworkflow_click" text = "associate Workflow"/> <asp: button id = "cancel" runat = "server" text = "cancel" onclick = "cancel_click"/> </ASP: Panel> </template_control> </wssuc: inputformcontrol> </template_inputformcontrols> </wssuc: inputformsection> </TD> </tr> </table> </ASP: content>
Finally, let's look at the background code. By expanding the code, we can see that vs2010 has automatically completed many things for us. We don't have to worry about data transmission, the tedious tasks of task list and history list. The main changes are inIn the getassociationdata () method.
It is used to save the data after XML serialization (form data transmission in the workflow is in the XML format)In spworkflowassociation. Therefore, a serialization method is required.
// This method is called when the user clicks the button to associate the workflow. private string getassociationdata () {arraylist listname = sp_peoleeditor.resolvedentities; datamodel = new datamodel (); foreach (pickerentity item in listname) {datamodel. persons. add (item. key);} datamodel. requestmessage = textbox1.text; string xmlresult = xmlserialize (datamodel); Return xmlresult;} private string xmlserialize (datamodel) {using (memorystream MS = new memorystream ()) {xmlserializer serializer = new xmlserializer (typeof (datamodel); serializer. serialize (MS, datamodel); byte [] bytes = new byte [Ms. length]; Ms. position = 0; Ms. read (bytes, 0, bytes. length); Return encoding. default. getstring (bytes );}}
Finally, datamodel is used to create a new data class to be passed in the project. You can create a class file, but note that the class must be labeled for serialization.
Using system; using system. collections. generic; using system. LINQ; using system. text; namespace heqichang. WF. demo1 {[serializable] public class datamodel {private list <string> persons; public list <string> Persons {get {If (persons = NULL) {persons = new list <string> () ;}return persons ;}set {persons = value ;}} Public String requestmessage {Get; Set ;}}}