XSN Inside Part 2: The Code Returns

After we get a basic overview of the files in the .xsn package, let's move onto something more interesting, something more code oriented.  Let's pretend that our company wants to have an Infopath form to gather information from several employees about the processes that they are supervising. Also the CIO wants all populated forms to have a submit button, which will transfer the information over to the SharePoint site. So at the very basic, our form looks like the following:

XSN1.gif

So the fields that we have in our form are the following:

  1. Comment: This field will store comments from the CIO or will display additional information about the from. This field will be read only for the users and will going to populate it from the Code.
     
  2. Reporter:

    • Description: here will set (from the code of course) the name of the reporter for which will be this template.
    • Field Type: Multiline Textbox
     
  3. Month & Year:

    • Description:This field will be date picker and the user will set the current date for which is the information
    • Field Type: Date Time Picker
     
  4. Provider:

    • Description: The provider is the name of the organization that provides the current information and services.
    • Field Type: Textbox
     
  5. Main table:

    • Description: This table contains the needed row data from the user based on the countries.
    • Field Type: table
     

Because this article is not going to focus on the InfoPath form (and much more for the code behind ), we will start from after the InfoPath form is developed.

So to give you some more understanding over the .xsn package let's populate the form and (not submit it) save it as it is in the following manner:

XSN2.gif

After that we save as the file with the following name and extension: mycode.xml.  To understand more about what this file is let's open it and take a quick look over the information that it stores.

XSN3.gif

So as you can see this .xml file is a result file, in other words when we submit our xsn form, Infopath is directly gathering the information and is generating the result.xml file which has the style and information that was populated.

So let's now open the xml file, not from the infopath but from the notepad using the  open with function. We'll see the following information:

XSN4.gif

As you can see, there are lot of tag they are separated in two main categories system and user, system categories are the tags which give system information to the infopath for example how to look like, where is the template and how to manipulate the information. One of the main System tags is:

<?mso-infoPathSolutionsolutionVersion="1.0.0.238" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Users\minevp\AppData\Local\Microsoft\InfoPath\Designer3\970a0bd2292a40f1\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?><my:Mainxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-07-30T19:57:12" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:xdServerInfo="http://schemas.microsoft.com/office/infopath/2009/xslt/ServerInfo" xml:lang="en-us">

This is the main tag which give to the system the following information:

  1. SolutionVersion- this attribute provide information about the version of the finfopath template file
  2. ProductVersion this gives information about which version is the infopath (2003 ,2007 or 2010)
  3. PIVersion="1.0.0.0" version of the generated file.
  4. href=file:///C:\Users\minevp\AppData\Local\Microsoft\InfoPath\Designer3\970a0bd2292a40f1\manifest.xsf – as you all know from the previous article the manifest.xsf contains information about the schema of the template.xml and as this current form is an instance from the template.xml(in other words this .xml form which we are seeing now is just the filled template.xml) this href is created when we first open our .xsn file and it stays there.
  5. Maintag (<my:Main>) is providing infromaiton about which namespaces are used in this xml document.

So if we look a bit down we can see the users tags; by users tags I mean the tags in which we had filled in the information for example:

<my:Account_Name>accc</my:Account_Name> - is populated the Reporter
<my:Month_Year>2011-10-14</my:Month_Year> -Month & Year :
<my:SPOC_NAME>SPOCH</my:SPOC_NAME –Provider

In other words, the tags are named by the textbox name that you have selected, in the same way the table is named:

<my:SAL1_GSD>1</my:SAL1_GSD>
<my:SAL2_GSD>1</my:SAL2_GSD>
<my:SAL3_GSD>1</my:SAL3_GSD>
<my:SAL4_GSD>1</my:SAL4_GSD>
<my:SLA1_ESM-INM>2</my:SLA1_ESM-INM>
<my:SLA2_ESM-INM>2</my:SLA2_ESM-INM>
<my:SLA3_ESM-INM>2</my:SLA3_ESM-INM>
<my:SLA4_ESM-INM>2</my:SLA4_ESM-INM>

The difference is that here we have a tag for every column in our case we have 4 columns so for every row there are 4 tags. With the populated information. So as you can see the filled row is looking like: and the empty row is looking like : <my:SLA1_ESM-CONM xsi:nil="true"></my:SLA1_ESM-CONM>
The xsi:nil="true" is giving information for the infopath form that the current field is empty.

So to summarize, for now we know the xml schema, xml files and where and what we can do with them. So our next step is to get some coding .In Part 3 of our workshop we'll examine the methods with which we can uncompres rewrite and compress the xsn file.
 

Up Next
    Ebook Download
    View all
    Learn
    View all