Step 9/20. Using ASXP forms in workflows
[24/11/2008] Update : I cover aspx association forms in step 14 with much more details.
Since WSS doesn’t allow the use of Infopath Forms , we will write our initiation form in “pure” aspx.
[Note: we will improve and extend this sample in the future]
We’ll start from step 8 solution.
In the U2UExpenseReport project, add a text file with an aspx extension : InitManager.aspx.
In source mode, copy and paste the following code fragment in the aspx page:
In design mode, the page will look like this:
Let’s add a new class, InitManager in a file InitManager.aspx.cs (make sure the class is public !).
Derive InitManager from the Page class :
Add the page directive at the top of InitManager.aspx:
We need to provide more details about the assembly of the InitManager class by adding an Assembly directive to the page; this directive has to know the assembly strong name, so recompile the project and retrieve U2U.ExpenseReport strong name (with Reflector for instance).
Add the Assembly directive before the page directive (don’t forget that my PublicKeyToken is different than your own):
Implement the Page_Load event handler:
Add a new protected member that will allow us to retrieve the textbox value of the .aspx page:
Add the corresponding using directive :
Modify the Page_Load event handler to display the manager:
Specify that the aspx page is the Initialization Form:
in the workflow.xml file, remove the <Instantiation_FormURN> in <MetaData>.
Modify the InstantiationUrl:
Modify the install.bat file to copy the aspx form(s) to the Layouts directory:
xcopy /s /Y *.aspx "%programfiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\"
Build the solution, call install.bat and test the workflow; the instanciation form should show up and when we click on the submit button whe should have a feeback.
Linking the form to the workflow
We want the workflow to be started when we click on the submit button.
We won’t interact directly with the workflow Runtime in Sharepoint but we interact with the site collection workflow manager (SPWorkflowManager class).
Here is the pseudo-code:
Web.Site.WorkflowManager.StartWorkflow(<listItem>, <associationTemplate>, <InitializationData>);
When Sharepoint will call our Initilialization form, it will provide some useful parameters :
· Request.QueryString["List"] which contains the List Guid.
· Request.Params["TemplateID"] which contain the association Guid.
· Request.Params["ID"] which contains the ListItem Guid.
Define the following members in the InitManager class:
And the corresponding using directives:
Upgrade the Page_Load code:
Rebuild, call install.bat and test the workflow.
Serializating the Initialization form data
Usually the iitialization form has several controls; the form data must be serialized in Xml and provided to the workflow.
Create a new class to encapsulate the Initialization form data:
Add a new helper class, AspxHelpers, with the following static methods:
In InitManager, add a new data member:
public class InitManager : System.Web.UI.Page
private InitFormData _initData = new InitFormData();
Upgrade the Page_Load event handler to serialize the form data and to start the workflow:
We need to upgrade the section of the workflow code which deserializes the data coming from the Initialization form.
Select the workflow in the Workflow Designer; double click on the first activity (onWorkflowActivated1) and replace the existing deserialization code with the following one:
Rebuild the solution, call install.bat and test the workflow.
[24/11/2008]Update : I cover aspx association forms in step 14 with much more details.
This hands-on training is the property of Redwood S.L sprl and may not be organized in class or in group without the prior written permission of Serge Luca. Should you wish to organize this hands-on training in your company or institution, please contact Serge Luca first to enter into a licence agreement. Each trainer or teacher using this hands-on training should have a licence agreement. Please ask your trainer or Serge Luca whether he or she has entered into a licence agreement with Redwood S.L sprl.
The hyperlink to this hands-on training may be placed on your website for free, on the condition that the name Serge Luca is clearly mentioned in the reference. Please send us a mail containing the link to the web page our reference is used on.