Modifying InfoPath manifest.xsf file from script (1/5)
In this five part series we’ll show the reader how to programmatically manipulate InfoPath form templates.
Part 1 of 5: The story
There are many scenarios where you might need to modify an InfoPath form template (.XSN) after it’s already in use. Let’s say the URL of your Web Service changes.
With InfoPath 2003 you need to change the URL manually:
- Open the form in design-mode (e.g. Right-click on the XSN and select Design).
- Extract files of the form template (XSN) into the temporary directory using File | Extract Form Files… , then close InfoPath
- Find manifest.xsf in the directory and open it in Notepad (or some other text editor).
- Find and replace all instances of existing URL with the new one.
- Save the modified manifest.xsf.
- Right-click the modified manifest.xsf, select Design, and finally use File | Save As... to save the form template as a XSN file.
With InfoPath 2003 with Service Pack 1 (SP1), just open the form in Design mode, go to Tools menu, select Change Data Source, and in the wizard locate the new URL.
But this isn’t (just) a sneaky way to convince you to download the SP1 Preview.
What if you are responsible for maintaining hundreds of InfoPath forms which rely on the Web service? Even with SP1 this would be a lot of work. It would be nice to do it programmatically.
The good news is that this is possible, even without SP1. The InfoPath XSN format is really a CAB file, and the files that make up the template are XML files which can easily be modified programmatically. You can pack/unpack a CAB file with help of extract.exe and makecab.exe utilities that are accessible for Windows users. Now the only things you need is to implement a small utility using script or managed code that will do the described above sequence automatically. Inside of the utility you should do the following:
- Unpack XSN file using extract.exe utility to the local temporary directory.
- Find manifest.xsf file and open it as a plain XML file.
- Replace the corresponding URLs using the XML DOM.
- Save the modified manifest.xsf.
- Pack all files into the XSN using makecab.exe utility.
- Clean up your temporary directory.
If you write a wrapper around this process to enumerate all the form templates, your hundreds of forms will be updated just in a few minutes.
Using this approach you can change not only URLs but SQL connection strings, files names, etc. If you want to learn more about the XSN format and the files that make it up, check out the InfoPath 2003 SDK. As always, be careful – save backup copies, test your code, test the templates before and after, etc.
At the end of this discussion, the patient reader expects a good sample that supports the idea explained above. And we will definitely do it in the following parts 2-5 of the series.
To be continued.
Comments
Anonymous
January 12, 2005
How to programmatically extract/manipulate/combine an InfoPath Template (XSN) file.Anonymous
December 19, 2006
用程序修改infopath的xsn模板文件Anonymous
May 23, 2007
转载:http://blog.csdn.net/yanwei100/archive/2006/12/20/1450535.aspx infopath模板介绍在infopath中,模板文件定义了i...Anonymous
April 01, 2008
PingBack from http://copyrightrenewalsblog.info/brian-jones-open-xml-formats-mapping-documents-in-the-binary-format/Anonymous
September 04, 2008
PingBack from http://panvega.wordpress.com/2008/01/05/modify-a-xsn-infopath-by-using-makecab-command/Anonymous
January 21, 2009
PingBack from http://www.keyongtech.com/1234942-best-practice-change-a-secondaryAnonymous
June 23, 2010
Hello thanks i have read the part 5 series i need to do exactly what you have mentioned. How to run this example for its written in script which script? I am having my infopath template in VS 2008(c#) do please tell me how can i use the example code can i have an independent tool which does all this using your script example? thanks