in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2010, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Corey Roth - DotNetMafia.com - Tip of the Day

Bringing you the latest time saving tips for SharePoint 2010, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2010

How to: Deploy a .UDCX file to a Data Connection Library

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.

UDCX

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.

UDCX2

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.

Comments

 

GuyO said:

This works well. - Until the connection is to a Sharepoint List. -- unlike column lookups in a sharepoint feature, infopath isn't smart enough to fix up a lists/foo reference.  I have been able to fix up the ListID Guid references using a featureEvent handler. I just finished testing the and deploying the solution and as soon as I can get it "cleaned" up for publcaton, I'll post the link,

September 18, 2009 7:29 AM
 

GuyO said:

I just discovered another reason for doing all of this in CAML vs a feature handler -- MSDN Article 931414 -- it's not possible to update the title of a udcx file after it has been deployed; so it has to be done in CAML as shown above.

September 29, 2009 10:22 AM
 

CoreyRoth said:

GuyO.

Actually I have discovered you can specify the list name for a SharePoint List in a .UDCX.  CHeck out this post.

www.dotnetmafia.com/.../specifying-a-list-by-name-in-a-udcx-file.aspx

October 6, 2009 9:38 AM
 

Camilo Vergara said:

How can I fix the empty title issue?

December 1, 2009 9:00 AM
 

CoreyRoth said:

I've actually run into the Title field not being populated before as well.  For some reason it doesn't pick it up from the CAML.  However, it does not affect the usability of the .udcx file.

December 1, 2009 9:14 AM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is a SharePoint Consultant for Stonebridge, Inc. specializing in clients in the Energy Sector.
2009 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems