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:
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:
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.
PingBack from http://copyrightrenewalsblog.info/brian-jones-open-xml-formats-mapping-documents-in-the-binary-format/
PingBack from http://panvega.wordpress.com/2008/01/05/modify-a-xsn-infopath-by-using-makecab-command/
PingBack from http://www.keyongtech.com/1234942-best-practice-change-a-secondary
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?