Thursday 6 June 2013

Deploy Data Connection File Via Feature

In our previous post we created an InfoPath form with two data connection files, we did this to separate our form from our server instance. We do this to attain a one step deployment process, that is we want our WSP package to deploy everything, I mean come on connecting to your production environment to deploy an info path form... kinda rookie.

So first off lets create a module to deploy our data connection file, download the one you put into your data connection Library. I'm just going to do the submitNewEmployee.udcx.

In your project add a module, remove the sample.txt file and add your submitNewEmployee.udcx file to the module.

With that complete, open up the elements file for your module, it should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <Module Name="DataConnectionModule">
  <File Path="DataConnectionModule\submitNewEmployee.udcx" 
        Url="DataConnectionModule/submitNewEmployee.udcx" />
We're going to make a couple changes to it:

  • Add the URL and Path to the module
  • Remove the Path from the file
  • Simplify the URL for the file, you specify it in the Module "Lists/DataConnections"
  • Add the Type and ignore properties to the file
  • Add a property node to the file

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <Module Name="DataConnectionModule" Url="Lists/DataConnections" Path="DataConnectionModule">
    <File Url="submitNewEmployee.udcx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
      <Property Name="Title" Value="submitNewEmployee" />
changes are highlighted in yellow.

Make sure, that your module is in the feature manifest, the right hand column.

After you deploy your project open up your data connection library to verify that your file was deployed. check the modified date to insure that you're looking at the most latest version and not just the one you uploaded from InfoPath.

now go ahead and download your submitNewEmployee.udcx file, open it up and take a look inside. the one thing that should stick out and burn your eyes is highlighted.
<?xml version="1.0"?>
<udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="">
  <udc:Description>Format: UDC V2; Connection Type: SharePointLibrary; Purpose: WriteOnly; Generated by Microsoft InfoPath 2010 on 2013-05-30 at 14:27:52 by yoursite\Administrator.</udc:Description>
  <udc:Type MajorVersion="2" MinorVersion="0" Type="SharePointLibrary">
    <udc:SubType MajorVersion="0" MinorVersion="0" Type=""/>
  <udc:ConnectionInfo Purpose="WriteOnly" AltDataSource="">
      <udc:ServiceUrl UseFormsServiceProxy="false"/>
      <udc:ServiceUrl UseFormsServiceProxy="false"/>
      <udc:FileName>Specify a filename or formula</udc:FileName>
      <udc:FolderName AllowOverwrite="0">http://yoursite/New Employee/</udc:FolderName>
    <!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication-->
Now that does not seem very dynamic, and that's because it's not, what we are going to have to do is in our event receiver open this file up, update the url and save it up again. I'll tackle that in my next post.