Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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...?

share|improve this question
    
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? –  Gennady Vanin Novosibirsk Jan 25 '13 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? –  ErinsMatthew Aug 24 '13 at 10:19
add comment

3 Answers

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

share|improve this answer
    
Since the question is specifically about infopath form I suppose. –  Robert Lindgren Aug 24 '13 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? –  Mohamed Derhalli Aug 24 '13 at 14:22
add comment

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.

share|improve this answer
add comment

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

http://www.codeproject.com/Articles/33228/Programmatically-create-a-browser-enabled-InfoPath

and, of course, there are many more via google

https://www.google.com/search?sourceid=chrome&ie=UTF-8&q=programatically+create+infopath+forms&safe=active

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

share|improve this answer
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 –  Gennady Vanin Novosibirsk Jan 25 '13 at 10:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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