29 April 2007

[InfoPath] How to modify the XSN file and the inside xml..

Introduction:

InfoPath is an XML based document that is saved in XSN format,,,,

The XSN is actually noting but a .Cab file (cabinet). Try renaming any XSN file to .Cab and click on it,,

You will find all files that actually consist an InfoPath file,,,

Problem:

Sometimes you need to modify the content of one of the files such as the schema file (.xsd)..

Process:

     The process goes as follows:

    Unpacking à Modifying à repacking

    This article will guide you through all three steps

Unpacking:

As we said before an XSN is nothing but a bunch of xml documents zipped in a cabinet…

So unpacking it is fairly simple,, you just need to:

  1. Rename your XSN file to .Cab
  2. Click on the cab file
  3. Select all files and right click on the selection…
  4. Select "Extract Files".
  5. Then choose a suitable place to extract the files in it,,,

Modifying:

Now what you need to do is to go the extracted folder and choose whatever file you want to modify in the XSN. Usually its notepad that you will use to modify these files..

After you finish save your work and close all editing applications.

Repacking:

    We need to zip al these extracted files into a cab or xsn file again so we can open our InfoPath file again,,,

    Now this is where you need to use a tool called Make-Cab which can be found in C:\Windows\System32\makecab.exe…

    

Note:

Using this tool is something I am to going to visit here in this article; I will just explain the part where repacking the files to XSN again,,,

But for more information in details on MakeCab.exe visit this link: http://support.microsoft.com/kb/310618/ where you can fid the SDK and download it,,,,

Let's get back to business. Till now you have all the extracted files in a folder, to create your XSN now follow the instructions:

  1. Create a txt file called directives.txt (or any suitable you like).
  2. Copy this code in the file:

    ;************************************************************

    ; MSDN Sample Source Code MakeCAB Directive file example

    ;************************************************************

    .OPTION EXPLICIT

    ;*****************************************************************

    ; change the value of the caninet name for example myInfoPath.xsn

    ;******************************************************************

    .Set CabinetNameTemplate=AfterRePackaging.XSN

    ;*************************************************************************************************************

    ; change the value of the Disk Directory Template value to the directory you want to store the xsn file into,,

    ;*************************************************************************************************************

    .set DiskDirectoryTemplate="D:\Workarea\InfoPath Work"

    .Set Cabinet=on

    .Set Compress=on

    ;*******************************************************

    ; Just List All the files to be added in the xsn file

    ;*******************************************************

    "D:\Workarea\InfoPath Work\Extracted Files\manifest.xsf"

    "D:\Workarea\InfoPath Work\Extracted Files\myschema.xsd"

    "D:\Workarea\InfoPath Work\Extracted Files\sampledata.xml"

    "D:\Workarea\InfoPath Work\Extracted Files\template.xml"

    "D:\Workarea\InfoPath Work\Extracted Files\upgrade.xsl"

    "D:\Workarea\InfoPath Work\Extracted Files\view1.xsl"

    ;*********************

    ; End of the File

    ;*********************

  3. Save your file. And open the command prompt (CMD).
  4. Now, you need to type the following command:

    MakeCab /f directives.txt

    *** be sure that you are in the same directory or give the full path name ***

  5. Congratulations now you have your XSN file go ahead and test it,,,

Conclusion and summary:

    You have learned in this article how to open an XSN file, modify it and re-package it again into XSN file,,

    Once you do this once, the other times will be piece of cake,,

And of course questions are always welcomed J

Cheers…

Filed under:
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Code Eater said:

Problem: Sometimes in InfoPath 2007 you need a way to limit a repeating field and putting for it Max

29 April 07 at 9:22 AM
# PC said:

thanks for the tip. your code has errors though.

need to remove the words "variable typos" that's stuck to OPTION EXPLICIT; need to remove the word "directory" just above .Set Cabinet=on

Thx!

22 November 07 at 1:16 AM
# Mirrored Blogs said:

Corpo: Olá pessoal, Aos geeks de plantão que já trabalham com o InfoPath 2003/2007 .... estou fazendo

28 December 07 at 1:23 PM
# Wael A. Kabli said:

Thanks PC,

corrrected...

31 December 07 at 6:13 AM
# Gilmour said:

Great post, was very useful.  Thanks A lot!

http://www.wiinjamod.com

29 February 08 at 12:25 PM
# Sayan said:

Is there a way to do this by managed code? I would like my application to achieve the same....but avoid calling the native makecab exe.

02 March 08 at 8:12 AM
# Sayan Ghosh said:

Hi,

I am trying to package a xsn template from a Visual Studio solution. Is there a way to embed the Formcode.cs, i.e. the managed codebehind to the xsn? Is there a better way to handle this from VS IDE?

06 March 08 at 1:33 AM
# Wael A. Kabli said:

Sayan,

sorry for not replying but honestly i am not aware of such thing, maybe there is an alternative way to do it though managed code..

25 April 08 at 5:33 AM
# windie said:

This is so cool, but if the form template contain a template signature, repaking will cause it lost.

10 November 08 at 2:38 AM
# Wael A. Kabli said:

if you want to do it with your hands (not programatically), its better that you:

1.save the XSN as resources in a folder

2.Close infopath

3.then modify what you need

4.right clicl on the manifist file and click on design

5. save as XSN again

10 November 08 at 5:11 AM
# Wor Tony said:

This worked for me when InfoPath form designre refused to open the xsn.

27 July 09 at 5:25 PM
# roxx said:

This is great! Thanks.

07 October 09 at 11:09 AM
# Michel said:

Exlenet post! you save my life!

04 December 09 at 6:37 AM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About Wael A. Kabli

I started working for Microsoft in 2006 after I graduated from King Fahd University of Petroleum and Minerals as a Software Engineer. Since then, I have joined Microsoft Consulting Services and started my career as an Information Worker and Application Development Consultant. A major portion of my work is helping our customers deploy and accelerate our technology adoption such as Microsoft Office SharePoint Server and .Net Framework. https://careers.microsoft.com/careers/en/gbl/ProfileWaelWE.aspx
Page view tracker