Thursday, December 31, 2009

The form template associated with this form was moved or cannot be accessed. The form template on your computer has the same form ID as the template

Many of you might have come across this shitty error while developing custom InfoPath forms and deploying them to SharePoint. I have spent ages in playing with InfoPath in troubleshooting this error and many others. I will explain quick fix for this error for the moment.

"The form template associated with this form was moved or cannot be accessed. The form template on your computer has the same form ID as the template associated with the form, but it is from a different location."

Now, lot of times you would deploy InfoPath form to SharePoint document library or content type using the Publish wizard feature. In my case I had to deploy my custom DIP (Document Information Panel) to a custom content type. Now I had written a feature receiver for content type which assigns my custom DIP to the content type once the content type is created by feature. Since I had developed InfoPath form on my dev machine and deploying it to dev SP site it complains about Form ID as in above error. This error means that when you developed a form on your machine and saved it, it has added a publishURL attribute as the saved location. Now even if you publish this form to SharePoint, the publish URL remains the same. So the buggy publishing wizard doesn't update this attribute. So when my document with custom DIP is opened it tries to fetch the InfoPath form from SharePoint location where publishedURL is a path on my machine where the form was developed and saved and it gets confused when trying to create it from SharePoint location.

So we know the fix now its easy : Remove the publishURL from the form isn't it?
YES and NO, the solution is easy but actually fixing it is not. To change this URL its pain in right place!!! If you use InfoPath designer option of "Save as source files" and then change the manifest.xsf and then save it again using InfoPath designer then the publishURL attribute is repopulated. So you have to do this removal outside of InfoPath.

Below are the steps to remove publishURL attribute from the form:
  1. Rename .XSN form to .CAB
  2. Extract all files from CAB file to a temporary folder.
  3. Open manifest.xsf file using Visual Studio or in a notepad.
  4. On the very first node (root node), remove name and publishURL attributes. Just get rid of those devils!!!.
  5. Now you need to repackage those files into a cab file - So we will use makecab.exe tool.
  6. Create text file in same location where your folder with extracted files are. Name it something like makefilename.txt. This file is like .ddf file if you have played with generating .wsp packages. Anyways, lets not get distracted, so what will go in this file? Well just copy following script and replace the names:
  7. ;************************************************************
    ; MSDN Sample Source Code MakeCAB Directive File


    .Set CabinetNameTemplate=Replacefilename.XSN

    ; Change DiskDirectoryTemplate to where you want the CAB/XSN saved.
    ;********Replace this path with your where you want to create the cab file********
    .set DiskDirectoryTemplate="C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates"
    .Set Cabinet=on
    .Set Compress=on

    ; List Every File You Want Added To The CAB (XSN)

    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\AO.xsl"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\Context.xml"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\Context.xsd"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\dc.xsd"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\dcmitype.xsd"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\dcterms.xsd"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\GetUserProfileByName1.xml"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\GetUserProfileByName3.xsd"
    "C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\min1\GetUserProfileByName4.xsd"

    ; End Of The File
  8. You will notice in your folder you have either more or less files to be packaged, if they are less then its easy to put them manually, but if the form is higly customised like mine was I had like 20 files to be packaged. You can get all the filenames in a text file easily by running DOS command from the folder location as mentioned below:
  9. dir "." /b >>fileListing.txt
  10. Now you can copy the filenames form filelisting.txt and place them in above makefilename.txt file with paths appended in front
  11. Now run makecab utility as: makecab /f C:\Documents and Settings\kk\Desktop\ContentTypes\DocumentTemplates\makefilename.txt
  12. You can find your new xsn file at the mentioned location.
Now in many cases this problem wouldn't arise because usually you publish the form directly from InfoPath. But since in my case I have to deploy everything as a package I have to make these changes in my .xsn file after it has been designed finally and then generate a deployment package. I will explain you in my next post on how to package your custom InfoPath DIP and apply it to you content type as part of a feature.