How to: Deploy a .UDCX file to a Data Connection Library
Posted
Thursday, May 14, 2009 10:08 AM
by
CoreyRoth
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.
<Feature
xmlns="http://schemas.microsoft.com/sharepoint/"
Id="{CE871E99-B9E8-4b3e-AF2B-D715C8AD08F0}"
Scope="Web"
Hidden="False"
Title="UDCX Deployment"
Description="This feature deploys a UDCX file to a data connection library."
>
<ElementManifests>
<ElementManifest Location="elements.xml" />
</ElementManifests>
</Feature>
I then have an elements.xml file like the one below.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="DataConnections" Url="Data Connections" Path="">
<File Url="test.udcx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="FALSE">
<Property Name="Title" Value="test.udcx"></Property>
</File>
</Module>
</Elements>
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"?>
<?MicrosoftWindowsSharePointServices ContentTypeID="0x010100B4CBD48E029A4ad8B62CB0E41868F2B0"?>
<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:Type>
<udc:ConnectionInfo Purpose="WriteOnly" AltDataSource="">
<udc:WsdlUrl/>
<udc:SelectCommand>
<udc:ListId/>
<udc:WebUrl/>
<udc:ConnectionString/>
<udc:ServiceUrl UseFormsServiceProxy="false"/>
<udc:SoapAction/>
<udc:Query/>
</udc:SelectCommand>
<udc:UpdateCommand>
<udc:ServiceUrl UseFormsServiceProxy="false"/>
<udc:SoapAction/>
<udc:Submit/>
<udc:FileName>Specify a filename or formula</udc:FileName>
<udc:FolderName AllowOverwrite="1">http://moss-server/MyFormLibrary</udc:FolderName>
</udc:UpdateCommand>
<!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication-->
</udc:ConnectionInfo>
</udc:DataSource>
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.