CREATING A WORKFLOW IN SHAREPOINT INFOPATH FORMSStep 1: Create an InfoPath form and publish the form in SharePoint Procedure for publishing the form1. Form options ->Compatibility 2. Go to Compatibility option and Select “Design a form template that can be opened in a browser or InfoPath. 3. In the below path with option “ Enter the url of a server that is running InfoPath forms services and can be used to verify compatibility :” Enter the path of the InfoPath form where the form should be published in SharePoint server.4. Under the Security and Trust option Select “Create Certificate” for the creation of the certificate for the Securing of InfoPath form.5. 6. In the Form options dialog box Click on the Programming. 7. Under the Browse button we can place the code file where we can write the code whenever a event is raised by clicking on the button or validation etc.8. We can write the code for example clicking on the submit form we can submit the data in sqlserver through SharePoint server also by following code.public void Submit_Clicked(object sender, ClickedEventArgs e) { try { SqlConnection SqlConn = new SqlConnection("Your connectionString”); SqlCommand SqlComm; string strid;string SampleId = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:Sample1/my:Total_Estimated_Value", this.NamespaceManager).Value; String Comm = "Insert into Sample1 values('" Sample1Value + "',);Select @@Identity;"; SqlComm = new SqlCommand(Comm, SqlConn); if (SqlConn.State ==ConnectionState.Closed) SqlConn.Open(); TenderId= SqlComm.ExecuteScalar().ToString(); //.ExecuteNonQuery(); if (SqlConn.State == ConnectionState.Open) SqlConn.Close(); XPathNavigator Table_Sample = MainDataSource.CreateNavigator().SelectSingleNode("/my:Sample1/my:Sampletext/my:Sample", NamespaceManager);9. The submission of data can be done by using the workflow procedure also.10. For the publishing of the InfoPath form to the server click on the file menu and click publish the form.11. The Publishing wizard will open 12. Select the Option “To a SharePoint server with or without InfoPath forms services”. And click next. 13. After clicking next write the SharePoint path where the InfoPath form is to be published. 14. After clicking next select the option “Enable this form to be filled out by using the browser”15. After clicking next The form will be published and now, after that below dialog box will be appeared with an option to browse the file to save the published form template. so give the name for the published form template.16. By clicking “publish” the form will be published. CREATION OF WORKFLOW 1. For the creation of work flow at first we need to create a source file for our “sample” InfoPath form.2. For this in the sample InfoPath form go to the file option. Select “Save as Source Files” and choose the destination where the files should be stored 3. Here in those files a file named “myschema.xsd” will be generated.4. We have to generate a cs file for using it in workflow by using the file “myschema.xsd”.5. For this go to visual studio command prompt and in that go to the file location where “myschema.xsd” is located in the command prompt.6. 7. Generate a cs file by using a command xsd myschema.xsd /c8. A file named “myschema.cs” is generated.9. Workflow can be created by opening visual studio and clicking on the “Sharepoint server sequential workflow”
10. Now we can get down to some coding! In the solution explorer double click on Workflow1.cs and up will open the workflow designer view. If you open up the toolbox you'll see three new groups of components, SharePoint - Workflow Tasks, SharePoint - Workflow, and Windows Workflow.
11. As you can see on the Workflow1.cs design surface it already creates the first workflow step for us with a onWorkFlowActivated action. This will always be the first Workflow action of any workflow. Below this action is an arrow and a kind of stop sign. We can drag and drop any new workflow actions from the tool box and place them on the arrow. Before we do that though there are a few properties we can check before we get going. If you go into the code view of Workflow1.cs you’ll see
using System;using System.ComponentModel;using System.ComponentModel.Design;using System.Collections;using System.Drawing;using System.Linq;using System.Workflow.ComponentModel.Compiler;using System.Workflow.ComponentModel.Serialization;using System.Workflow.ComponentModel;using System.Workflow.ComponentModel.Design;using System.Workflow.Runtime;using System.Workflow.Activities;using System.Workflow.Activities.Rules;using Microsoft.SharePoint;using Microsoft.SharePoint.Workflow;using Microsoft.SharePoint.WorkflowActions;using Microsoft.Office.Workflow.Utility;using System.Xml;using System.Xml.Serialization; namespace SharePointWorkflow1{ public sealed partial class Workflow1 : SequentialWorkflowActivity { public Workflow1() { InitializeComponent(); } public Guid workflowId = default(System.Guid); public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties(); public string field1 = default(string); private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e) { SPListItem SPLISTSample = workflowProperties.Item; SPFile SPFileSample = SPLISTSample.File; XmlSerializer SampleSerializer = new XmlSerializer(typeof(myFields)); XmlTextReader SampleReader = new XmlTextReader(SPFileSample.OpenBinaryStream()); myFields SampleForm = new myFields(); SampleForm = (myFields)SampleSerializer.Deserialize(SampleReader); field1 = SampleForm.field1; sampledatasetTableAdapters.sample1TableAdapter Sample_Adptr = new SharePointWorkflow1.sampledatasetTableAdapters.sample1TableAdapter(); int SampleId = Convert.ToInt16(Sample_Adptr.Insert(field1)); } }}
12. Here we have to add “myschema.cs” file to our project.
13. And write the above given code when we run the work flow the workflow will be activated and the project will be executed