The other day I saw that @mrackley was looking for a way to deploy a .UDCX file to a data connection library. Having CAML still fresh in my mind from the talk Kyle Kelin and I did on Monday, I decided to see if I could get the job done using the Module and File elements. Sure enough, I found a simple way to deploy the .UDCX file. Here is what it looks like. For the purpose of my example, I am going to deploy a file test.udcx to a data connect library at the /Data Connections path in my current site. Adjust your paths accordingly. I have a simple Feature.xml.
Description="This feature deploys a UDCX file to a data connection library."
<ElementManifest Location="elements.xml" />
I then have an elements.xml file like the one below.
<Module Name="DataConnections" Url="Data Connections" Path="">
<File Url="test.udcx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="FALSE">
<Property Name="Title" Value="test.udcx"></Property>
The Name attribute of the Module element really doesn’t matter, but the Url does. Set this to the relative path of your data connection library. I then use a File element and set the Url attribute to the name of my file. Here you will notice I tried to set a property on the file and although it was not successful in setting the Title property of the form, simply having it there allowed the data connection library to properly read the file as a universal data connection file instead of an Office data connection file.
This is what my data connection file looks like. It’s a simple file that controls where the submit action goes to.
<?xml version="1.0" encoding="UTF-8"?>
<udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="http://schemas.microsoft.com/office/infopath/2006/udc">
<udc:Name>SharePoint Library Submit</udc:Name>
<udc:Description>Format: UDC V2; Connection Type: SharePointLibrary; Purpose: WriteOnly; Generated by Microsoft Office InfoPath 2007 on 2009-05-14 at 9:29:23 by MOSS-SERVER\croth.</udc:Description>
<udc:Type MajorVersion="2" MinorVersion="0" Type="SharePointLibrary">
<udc:SubType MajorVersion="0" MinorVersion="0" Type=""/>
<udc:ConnectionInfo Purpose="WriteOnly" AltDataSource="">
<udc:FileName>Specify a filename or formula</udc:FileName>
<!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication-->
Here is what it looks like once the feature was activated.
As you can see the title field is blank but other than that it seems to work fine. I’ll also point out that the file is automatically set to Approved status when uploaded this way. Here are the properties. You can see that it correctly picked up that it was a WriteOnly connection for a SharePointLibrary.
Kyle and I debated in our talk if CAML or the API was better for provisioning sites and what not on Monday night. I certainly think this solution is a lot better than writing code. It’s simple and very quick to implement. The Module and File elements are very powerful and you can use them to deploy just about any kind of file. I’d like to figure out how to get the Title field set properly, but it’s not a deal breaker for me right now.
Follow me on twitter.