Thursday, November 24, 2011

Programming InfoPath Forms 2007 - Part 1(Creating the Infopath Form Project)

We all know the power of Infopath Forms, everyone simply Love them, they are sleek, easy to use and end users also finds them interesting.

But for Developers, ahh dont tell me, if you believe ---> "They are Easy to Code" and Debug with SharePoint Process w3p.exe??

Actually it is not as simple as we think, from my exeriences with this blog, i will share what i do normally.

This will be 3 parts series and in 1st part we will create the Base, "The Project containing Code".

Many of times when a newbie code with VSTA, he gets confuse how can i attach the process to debug the code and why VSTA is opening VS 2005, by default, so in this post, i will show you how can we create a VS 2008 Code Project for Infopath Forms.

With this as well we have a Case Study, which will remain there for all three Posts.

These Posts are not about designing forms, so i believe if you are reading this then you must be aware of designing Infopath Forms.

Here we will use a very simple Case Study:
  • In a Company namely "Lorem Ipsum" :).. Scrum Follows, and everyday a manager assigns Tasks To his associates, on work they have to perform, Manger uses an Infopath form, to create multiple tasks for his associates.
So Keeping this in mind, i have developed a solution simmilar.

SO Lets Look into it:

1)Team Site:We will have a sharepoint site, can take a Team Site, with Enterprise Features Activated.
2)Infopath Form Library:
We will have  an Infopath Form Library “TasksCreator”,namely .
3)Task List: For assigned Tasks we will use Default Team Site Tasks List.
Infopath Form Design:

Please follow these Points to Design the Form:
1)    Open Infopath 2007 Designer and click Design a Form Template:
Choose Blank from Infopath Form Template Options:
Don’t Forget to “Enable Browser Compatible Features Only”.
2)Next we will Design our Form , so that i will contain a repeating table a check box and a manager textBox like this:

Remember, we are not giving importance to the way form is designed, instead we want  to give prefference to Coding, so go ahead change the way it looks .


So here is how  My Data Source is Presently:


·         managerName: Manager’s Name-Text
·         assignTaskCheck- CheckBox Value True/False
·         Entry: Section
  • Group7: Repeating Table
·         Group1: Contact Selector
·         TaskDescription,DueDate,DateComplete
·         targetSite(V. Important) : To get the current Web url on which this form is running, instantiating SPSite object
among all of these targetSite is very important field, in this we will store the target site and use its url to instantiate SPSite object in our code..

For details on how to add Contact Selector in

Now Comes the Action Part: Coding this Form to perform our Action:

Here are the Steps we will follow to do this for us:
1)Modify Trust Level

Go To Tools in the Menu, from there go to Form Options and select “Security and Trust”, uncheck Automatically Determine Security Level and then select “Full Trust”.

2)Change The Coding Language for VSTA
I am a C-Sharper, so I will choose C#, you will find this in” Programming “ section of Form Options:

Also at a point of time if you feel that you need to remove the code, then you can do this by clicking Remove Code Button.
3)Make Data Connections:

Before Starting Coding we will create two Connections and Manage Submit Options,

a)Context: For Contact Selector, as you can find details in the link

b)“SharePoint Library Submit”- This we will use to modify later with our code to submit our form in the library, for now just create it as follows:
Go to Data Connections then select "To Submit Data to Document/ Form Library"

For Now just Give any Form Library in the Site, later we will modify it using code.


I have Given File Name with a Format: concat(managerName, "-form", today())
you can choose different way, and do check Allow Overwrite if file exists. That’s it finish it by doing next twice.

4)Enable Submit Options:

Go To : Tools in Menu, Submit Option and Configured as below, choose Perform Custom Code action,

Press Edit Code. Save the form if its prompted and then it will open VSTA -2005 Code for you in VS-2005 Environment,

Don’t do anything now just Save it, and if asked , press ok in the submit Options in Infopath Designer and Save the code .

5)Now Lets Convert Our Code in the VS-2008 Code.

Go to the Infopath Designer click on Submit Button and in Button Properties in Action Drop Down Choose Submit, and that’s it. We are now ready with coding work. Save The Form.

Close the VSTA , VS 2005 project, do copy the directory path of it, and open then open VS-2008.Or Just Change the Location of the Project and then open it in VS2008, It Will ask you to Upgrade the Project, Please do that and that’s it we are done with it.
It Will Get Upgraded, Now Close The Project.

* Save  Form as Source Files:
Next, we will Extract the Form Source Files and save it in a Folder as “Infopath Form Template” Open the Form in Infopath Designer 2007, Go to File then choose Save as Source Files.


NOTE: Please Do Follow the Same Name of the Folder as we have choosen.

Now Copy that Folder and Place in the Project that we upgraded above at root.

* Open the Project in VS 2008.Open the project again and “Click show all files”, then you will be able to see Infopath Form Template folder, include the folder in the project.

Rebuild The Project, and you can see pdb and dll created in the same folder.

If .pdb files are not created then check if the Project is in Debug mode and Debug Config should Be Full.

For this , go to Project Properties, their select “Build” and from there choose Advanced option in the lower right corner, and in output for Debug Info Change Drop Down Value to full, see below:


Save the Project and Now we are ready with the upgrade and its finally a Infopath Form SharePoint Compatible VS-2008 Project. You can now see that VS 2008 contains all Designer Menu Items and Options.

Data Source and rest of Properties are enabled in the same VS2008,

Open Manifest.xsf file in Infopath Form Template Folder, so here we have over Designer Enabled here in you can see the form right there in VS2008.:

Go To Second Part of this Blog to see how to do coding  with this  to achieve our Case Study.

  • It Contains a Manager Name Text Box(We will use it for Naming the Form), as per logic it contains name of manager who will assign multiple tasks to his associates.
  • "Assign Action Item" Check Box, If Checked then our repeating table will get appear and manager can create multiple Tasks in it , it will look like this: