I have an InfoPath form published to a library... I need to create forms dynamically with siteuser as form name... I need to achieve it in Object Model... Can any of you help me on this...?

  • If you are NOT using enterprise Sharpoint server, I do not think it is possible. IMO, it is possible only for browser-enabled IP forms, i.e. through IPFS - Sharepoint Server Infopath Forms Services. Is it your caee? Commented Jan 25, 2013 at 10:18
  • @Paddy: If this question is still relevant to you, please add some clarifying information. Are you wanting to create a new InfoPath form solution that others can then fill out, or create completed forms based on an existing template? Commented Aug 24, 2013 at 10:19

3 Answers 3


If you want to create form instances programmatically, I have done this recently with some relative ease.

As aforementioned, the XSN is a cab file. You need to use the Microsoft.Deployment.Compression and Microsoft.Deployment.Compression.Cab assemblies (which you can get here: http://wixtoolset.org/) to be able to read the cab file in memory (as opposed to saving it out to the file system first. Best to keep things in Streams in memory if at all possible).

Within the cab file, there is a file called template.xml which represents an empty form instance of that Form template.

Once you have that, you can then use standard XML techniques to populate fields in the my namespace.

You will also have to set the form save location to the full URL of the library where the Form's content type has been added. I can't remember off hand what the name of that node in the XML is, but it's one of the first nodes in the file, in a section just before the my namespace. You'll also need to generate a unique ID for the form (and this node is in the same section as before, the next node after the save URL), and this unique ID is just a GUID without the dashes, and in uppercase.

Once you've done all that, just use the SharePoint object model to write this completed XML to your library, using whatever name you want (just save with extension .xml). Ensure you keep the 'mso' namespace elements at the top of the file as this tells SharePoint what XSN file to use to render your form.


InfoPath forms certainly can be programmatically built - that was one of the motivations of the change from the old office file formats (.doc, .xls etc) to the new (docx, xlsx etc)

These new formats are, in essence, cab files filled with XML-based data and manifests specifically designed to make object model manipulation easier.

Now, I don't exactly know what you want in entirety, but there are plenty of tutorials around to get started in creating forms programmatically. Such as this one from CodeProject


and, of course, there are many more via google


Is that what you meant, or was it something different you were after?

  • 1
    "that was one of the motivations of the change from the old office file formats (.doc, .xls etc)". Infopath forms are XML based and I do not recall that their format was changed since 2005, i.e. before docx, xlsx introduction Commented Jan 25, 2013 at 10:15

Why don't you have your form published as a content type in your site, and add a new document (item) with the user's specific name to that library out of this content type? At the end all content types in SharePoint inherit from the item content type, and you can easily add new item to SharePoint list programmatically if you already have your form deployed.

I haven't tried it yet, but my guess it should work

  • Since the question is specifically about infopath form I suppose. Commented Aug 24, 2013 at 12:58
  • Yes, but he has the InfoPath form already there as a template! So it will be up to SharePoint to create a new form when you add new item to the Form Library from Form's Content Type programmatically, right?
    – user19105
    Commented Aug 24, 2013 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.