Automatically publish InfoPath form to SharePoint

I have a working solution to create an InfoPath form from a Lotus Notes form. It’s good; but I want to make it great. I also need a feature to automatically publish the InfoPath form. It’s rather tedious to publish a form through the InfoPath client. It would be painful to do that for 100+ forms.

So I searched around for some solutions and found some that were interesting. I started with this posting:

http://www.sharepointblogs.com/koning53/archive/2007/10/16/infopath-vsto-post-build-steps.aspx

I added code to my migration solution to create a batch file and run it. The content of the batch file appears below.

“C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe” -o deactivateformtemplate -url http://litware/ -filename “C:\Documents and Settings\Administrator\My Documents\InfoPath\SharepointPoC.nsf\Issue\cab\Issue.xsn”
“C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe” -o execadmsvcjobs
“C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe” -o uploadformtemplate -filename “C:\Documents and Settings\Administrator\My Documents\InfoPath\SharepointPoC.nsf\Issue\cab\Issue.xsn”
“C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe” -o execadmsvcjobs
“C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe” -o activateformtemplate -url http://litware/ -filename “C:\Documents and Settings\Administrator\My Documents\InfoPath\SharepointPoC.nsf\Issue\cab\Issue.xsn” 

I can dynamically create the batch file. The batch file has to run on a machine running SharePoint 2007 server. The batch file should remove a previous InfoPath form if it exists. It will post the new InfoPath form to the SharePoint server. The new InfoPath form should then be activated.

Unfortunately, I am getting an error when running some of the stsadm commands:

     The following form template cannot be found: urn:schemas-microsoft-com:office:infopath:Issue:-myXSD-2006-01-01.

So I need to figure out what is wrong here.  I’ll have to spend more time researching and debugging it.

The other interesting item I found is the mentioning of a best practice. On page 951 of “Designing Forms for Microsoft Office InfoPath and Forms Services 2007”, it mentions that administrative-deployed form templates generally exhibit slightly greater performance than equivalent user-deployed  forms. So I’ll take this approach to get a little more performance using Forms Services.

Transforming a Rich Text field from a Lotus Notes form to Infopath

Transforming a simple text field from a Notes form to an InfoPath form is relatively easy. So how do I take a Notes Rich Text field and transform it into a InfoPath Rich Text field? Also, how do I ensure it will work on a web form? This is not so easy and it may not always work if the Notes Rich Text field contains embedded objects or file attachments. But let’s just look at the design for now.

The design of a rich text field in a Lotus Notes form appears as follows:

Rich Text Field Design

Rich Text Field Design

 

 

 

The design details of the same rich text field (with the label) appear in the DXL file as follows:

<par>
<run><font size=’12pt’ style=’bold’ name=’Segoe UI’ pitch=’variable’
 truetype=’true’ familyid=’20’/>Detailed description:</run>
</par>

<par>
<run><font size=’12pt’ name=’Segoe UI’ pitch=’variable’
 truetype=’true’ familyid=’20’/>
<field type=’richtext’ kind=’editable’ name=’Details’/></par>

 

A Rich Text field in the InfoPath Designer class appears as follows:

Rich Text Field in InfoPath Designer Client

Rich Text Field in InfoPath Designer Client

 

 

 

 

You can right-click on the field and select Properties to view the settings for the field. The Display tab indicates that “Only full rich text without embedded images is supported in browser-enabled form templates.” So this will be a problem for any rich text fields in Lotus Notes documents that have embedded images.

Rich Text Box Properties

Rich Text Box Properties

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

It is not as easy to define the Rich Text field in InfoPath. There are multiple files that must be updated:

view1.xsl: This defines how the field will be displayed in the form

<div align=”left”>
 <font style=”FONT-WEIGHT: bold” size=”3″>Detailed description:</font>
</div>
<div align=”left”>
 <font size=”3″></font>
 <span class=”xdRichTextBox” hideFocus=”1″ title=”Details” contentEditable=”true” xd:binding=”my:Details” tabIndex=”0″ xd:xctname=”RichText” xd:CtrlId=”CTRL12″ style=”OVERFLOW-X: visible; WIDTH: 100%; WHITE-SPACE: normal; HEIGHT: 50px”>
  <xsl:copy-of select=”my:Details/node()”/>
 </span>
</div>

myschema.xml: controls the schema reference

<xsd:element name=”myFields”>
 <xsd:complexType>
  <xsd:sequence>
   <xsd:element ref=”my:Details” minOccurs=”0″/>
  </xsd:sequence>
  <xsd:anyAttribute processContents=”lax” namespace=”http://www.w3.org/XML/1998/namespace”/>
 </xsd:complexType>
</xsd:element>
 <xsd:element name=”Details”>
  <xsd:complexType mixed=”true”>
   <xsd:sequence>
    <xsd:any minOccurs=”0″ maxOccurs=”unbounded” namespace=”http://www.w3.org/1999/xhtml” processContents=”lax”/>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
</xsd:element>

 sampledata.xml: specifies the default values that should be displayed to the user when first loading the InfoPath form

 <my:myFields xmlns:my=”http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-10-02T12:31:13” xmlns:xd=”http://schemas.microsoft.com/office/infopath/2003“>
 <my:Details/>
 <xd:SchemaInfo LocalName=”myFields” NamespaceURI=”http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-10-02T12:31:13“>
  <xd:Namespaces>
   <xd:Namespace LocalName=”myFields” NamespaceURI=”http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-10-02T12:31:13″/>
  </xd:Namespaces>
 </xd:SchemaInfo>
</my:myFields>

manifest.xsf: include a reference to the View file and special editing settings

 <xsf:views default=”View 1″>
  <xsf:view name=”View 1″ caption=”View 1″>
   <xsf:editing>
    <xsf:xmlToEdit name=”Details_1″ item=”/my:myFields/my:Details”>
     <xsf:editWith type=”rich” autoComplete=”no” component=”xField” proofing=”no”></xsf:editWith>
    </xsf:xmlToEdit>
   </xsf:editing>
   <xsf:mainpane transform=”view1.xsl”></xsf:mainpane>
  </xsf:view>
 </xsf:views>

See http://www.sharepointsecurity.com/content-201.html for more details on the architecture of the InfoPath Template (XSN).

I have not even given attention to adding columns to display the data yet. But you should get the impression that automating the transformation of a field is a bit complex; especially if you want it to display properly in a web form.

Hiding sections in an InfoPath form

 I was trying to figure out how to hide sections like in a Lotus Notes form. So I came up with the following solution. The form design is displayed below:
form design

form design

 

 

 

 

 

 

I have two buttons and a section. The section contains some field labels and fields. Clicking on the Hide button will hide the section from the user. Clicking on the Display button will display the section to the user.

I added an attribute field named “hideContactSection” as a data source. The data type is defined as True/False (boolean). The default value is “0”.

Data source
Data source

 

 

 

 

 

 

 

The attribute field is defined in the template.xml file as follows:

<my:myFields my:hideContactSection=”0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:my=”http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-24T22:36:36” xmlns:xd=”http://schemas.microsoft.com/office/infopath/2003“>

The Hide button contains a Rule named “Hide Contact Section”. The rule sets the value of the hideContactSection attribute to “1”.

Hide section rule

Hide section rule

 

 

 

 

 

 

 

 

 

 

 

The Display button contains a Rule named “Display Contact Section”. The rule sets the value of the hideContactSection attribute to “0”. Both rules are defined in the manifest.xsf file.

The unbound controls section defines that rules exist for each button.

   <xsf:unboundControls>
    <xsf:button name=”CTRL_Button_Hide”>
     <xsf:ruleSetAction ruleSet=”ruleSet_1″></xsf:ruleSetAction>
    </xsf:button>
    <xsf:button name=”CTRL_Button_Display”>
     <xsf:ruleSetAction ruleSet=”ruleSet_2″></xsf:ruleSetAction>
    </xsf:button>
   </xsf:unboundControls>

The rulesSets section defines the details of each rule.

 <xsf:ruleSets>
  <xsf:ruleSet name=”ruleSet_1″>
   <xsf:rule caption=”Hide Contact Section” isEnabled=”yes”>
    <xsf:assignmentAction targetField=”@my:hideContactSection” expression=”&quot;1&quot;”></xsf:assignmentAction>
   </xsf:rule>
  </xsf:ruleSet>
  <xsf:ruleSet name=”ruleSet_2″>
   <xsf:rule caption=”Display Contact Section” isEnabled=”yes”>
    <xsf:assignmentAction targetField=”@my:hideContactSection” expression=”&quot;0&quot;”></xsf:assignmentAction>
   </xsf:rule>
  </xsf:ruleSet>
 </xsf:ruleSets>

The section has a conditional format defined in the section properties tab. The section is hidden from the user when the hideContactSection attribute has a value of “1”.

Conditional format for section

Conditional format for section

 

 

 

 

 

 

 

 

The details of the conditional format is stored in the view1.xsl file. An xsl:if statement tests the value of the hideContactSection attribute to determine if the section should be displayed or not.

 <xsl:template match=”my:ContactSection” mode=”_2″>
  <xsl:if test=”not((../@my:hideContactSection = &quot;1&quot;))”>

I am using buttons in this example because it is easier to understand. I could change how the attribute value is set. Or I could use a different conditional format option. But this seems like a good place to start.