Winsmarts.com

Microsoft MVP

MVP Logo

Awarded the Microsoft MVP Award.

Hosted By

blah!bLaH!BLOG!!

Deploying InfoPath 2007 Forms to Forms Server – Properly!

Posted on 8/21/2008 @ 2:14 PM in #Sharepoint | 13 comments | 5645 views

Okay so, the catchphrase/keyword here is “properly”. This begs the question, what is improper?

See in InfoPath 2007, if you read all the docs, books, and even MSDN, they ask you to craft an InfoPath form, and then go through the publishing steps. Specifically, the docs call you to publish “To a SharePoint Server with or without InfoPath Forms Services”.

Hmm .. that’s good except, developers don’t deploy – infrastructure guys do.

My new motto is “If I can’t deploy properly, the feature doesn’t exist”.

So I am glad to say, that deploying infopath 2007 forms to forms server as web based forms is a feature that does exist – i.e. – you CAN package them up as features and solutions, and deploy them like god intended mankind to.

Here is how you can create and publish such a form.

  1. Craft up your InfoPath Form – try and avoid certain features (too many to list here).
  2. Publish it to “a network location”. This is a file on your disk.
    1. Ensure that while publishing to a network location, when faced with this question “if all form users can access the location that you entered .. “, blank out the textbox – you do not want the information of “where the form lives”, to be embedded in the form – you want that information to be embedded in the feature.
  3. Great – now with the form published, craft up a visual studio solution, that will act as your InfoPath form/content type deployer.

Here is how you can craft up such a feature.

  1. Craft up a project structure like this (this is a class library) -
  2. In feature.xml, put in the following code -
  3.    1:  <?xml version="1.0" encoding="utf-8" ?>
       2:  <Feature xmlns="http://schemas.microsoft.com/sharepoint/"
       3:           Id="41CEE181-9440-4536-A1DA-73F41D2155B7"
       4:           Title="My Form"
       5:           Description="This feature deploys the browser enabled InfoPath Form."
       6:           Version="12.0.0.0"
       7:           Scope="Site"
       8:           DefaultResourceFile="ipfscore"
       9:           ReceiverClass="Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver"
      10:           ReceiverAssembly="Microsoft.Office.InfoPath.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" >
      11:      <ActivationDependencies>
      12:          <ActivationDependency FeatureId="C88C4FF1-DBF5-4649-AD9F-C6C426EBCBF5"/>
      13:      </ActivationDependencies>
      14:      <ElementManifests>
      15:          <ElementManifest Location="element.xml"/>
      16:          <ElementFile Location="MyForm.xsn"/>
      17:      </ElementManifests>
      18:      <Properties>
      19:          <Property Key="FeatureName" Value="My InfoPath Form Template Feature"/>
      20:      </Properties>
      21:  </Feature>
    1. If you note, in the above, there is a receiver class that takes the responsibility of extracting the content type, and ensuring that the content type is browser renderable. How it does that? Heck I don’t know – the reflector code is obfuscated. I’m guessing it’s the equivalent of setting something in the database directly, which I shouldn’t be touching anyway. Except I know it works, and this is a supported mechanism because MSFT uses this all over the place.
    2. Secondly, if you note, There is an activation dependency. The dependency is ensuring that you have enterprise features turned on. That’s it.
  4. In the elements.xml put in the following code –
  5.    1:  <?xml version="1.0" encoding="utf-8" ?>
       2:  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
       3:      <Module Name="XSN" Url="FormServerTemplates" RootWebOnly="TRUE">
       4:          <File Url="MyForm.xsn" Name="MyForm.xsn" Type="GhostableInLibrary"/>
       5:      </Module>
       6:  </Elements>
    1. As you can tell, I am simply copying over the MyForm.xsn over to a place called ~site/FormServerTemplates. If you view the SharePoint file system on the site (i.e. inside the content db), you will see that FormServerTemplates is a special place where templates for content types exist.
  6. Your Install.bat looks like this –
  7.    1:  @SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
       2:  @SET GACUTIL="c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe"
       3:  @SET WSPPBUILDER="C:\Code\WspBuilder\WspBuilder.exe"
       4:   
       5:  @echo off
       6:  Echo Creating Solution Package
       7:  %WSPPBUILDER% -outputpath solution -Excludepaths bin
       8:   
       9:  Echo Retracting Solution
      10:  stsadm -o retractsolution -name MyForm.wsp -immediate
      11:  stsadm -o execadmsvcjobs
      12:   
      13:  Echo Deleting Solution
      14:  stsadm -o deletesolution -name MyForm.wsp
      15:   
      16:  Echo Adding Solution
      17:  stsadm -o addsolution -filename Solution\ MyForm.wsp
      18:   
      19:  Echo Deploying solution
      20:  stsadm -o deploysolution -name MyForm.wsp -immediate -allowGacDeployment -force
      21:  stsadm -o execadmsvcjobs
      22:   
      23:  Echo Resetting IIS
      24:  IISRESET
    1. As you can tell, I’m a fan of WSPBuilder. You should be too.
  8. Modify your project to call Install.bat at successful builds.
  9. That’s basically it. Build & Deploy.

How to use it?

  1. Create a Forms Library
  2. Go to its Settings à Advanced Settings. Choose to allow management of content types, and choose to open “Browser Enabled Documents” in Web Pages, rather than the Client Application.
  3. After having deployed the solution & activated the feature, you will see that there is a new content type called available called “MyForm”. Use that content type as the default content type of the document library you created above in Step #2.
  4. Delete the default “form” content type.
  5. That’s it – click “New” and the form should be running browser enabled. w00t!

How to deploy to production?

Simple – hand over the .wsp to your infrastructure guy, turn your phone off, and go have a smoke (or chew gum – whatever might be your thing).


On 8/21/2008 2:40:07 PM stephane eyskens said ..
Hi, Good post! Thanks for sharing it!

On 8/27/2008 1:39:57 PM TJ said ..
Much agreed, great post. I do however have one issue. I have an InfoPath form which when deployed using a solution throws an error "The XSN can not be used on server" After searching I thought the problem was to do with the security settings. I removed existing data connections to SharePoint lists on another domain thinking that would fix the issue (cross domain being the problem). However the problem persists when deploying in a solution format. It is worth mentioning that although it is failing via a solution using the InfoPath publishing wizard works fine.

On 8/28/2008 9:52:16 AM TJ said ..
Answer to previous question. Read blogs properly and don't shortcut. Basically I hadn't published the form to a network location. Thanks.

On 9/11/2008 11:24:32 AM Christina Odom said ..
Excellent post. Have you done this with forms that are to be Content Types?

On 9/11/2008 7:02:09 PM Sahil Malik said ..
Christina - Yep it'll work!

On 9/12/2008 10:08:51 AM Lawrence said ..
Nice post, only thing is that for me it doesn't end up as a content type. I get the file into the FormServerTemplates-folder but it never shows in the content type dropdown. I have activated features and done everything acording to your instructions 4 times now but no luck. Any idea as to why it won't show? Btw we're doin this on WinServ2008 with MOSS2007 SP1, VS08 SP1 and Office2007.

On 9/18/2008 12:36:46 PM Christina Odom said ..
So random question. From a maintainence standpoint, if this feature is part of a larger solution package (think site definitons, content types, etc), would just uploading the updated .xsn file to CA be enough (as with standard admin-approved forms?) or would you have to rebundle and upgrade the solution package every time?

On 9/19/2008 8:26:11 AM Sahil Malik said ..
Uploading won't be enough!

On 10/15/2008 4:50:50 AM Raul Queiroga said ..
Excelent post, it was what I was looking for. Now for another, imagine I want to create a list definition that uses the content type deployed in that feature. How do I set the ID of the fields in the view element of the schema.xml since I only know them after the form is deployed (the purpose is a solution package with both features)?

On 10/21/2008 7:25:31 PM Ashley Frank said ..
Christina, Uploading xsn and approving was enough for me to get the content type to show.

On 10/29/2008 5:13:14 PM RJ said ..
Unable to view the item for "Craft up a project structure like this (this is a class library) - " I am a newbie and would like learn how to create a solution.wsp file. Can you direct me to the right place?

On 11/10/2008 2:04:59 AM suja said ..
Hey great post!!
I was looking for exactly same thing to publish my 10+ infopath forms in various servers.
Now my problem is how to handle the code behind dlls for each form?

On 11/19/2008 2:02:54 PM Jonathan K. Herschel said ..
http://img170.imageshack.us/img170/7963/capturetb7.png seems to be missing. Can you fix?
thanks!

Please post your comments:


Your feedback will be submitted for moderation, and will appear after it is approved.

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Site designed and maintained by Sahil Malik | All Rights Reserved. ©2007 WinSmarts.com.