Programmatically Create an InfoPath form with ASP.NET
I worked on a project a while back where I needed to develop a .NET based web application that collected data and submitted the results as an InfoPath form in a SharePoint form library. It had some very cool features (like binding dropdowns to SharePoint lists and hiding/showing administration fields based on SharePoint security... this allowed all adminstration to be done with the SharePoint UI). The coding was loosely based on this posting (http://www.bizsupportonline.net/infopath2007/programmatically-create-infopath-form-console-app.htm) which I found to be a solid framework.
Anyway, getting things to sync nicely was a bit of a pain (from InfoPath version number matching to data formatting for dates) but, in the end, all worked well. Except… We were seeing issues with posting an InfoPath form when the associated XML exceeded a certain number of characters. When things worked, the form posted and worked cleanly with the InfoPath client. When we appeared to exceed our character limit, the data posted to the form library but as an XML document (different file icon) and could not be read by InfoPath. Looking at the XML itself with WordPad showed the addition of a special character at the end of the file. After a couple of hours of head scratching (OK, maybe it was a couple of days) I solved it.
Using the code example in the link above, I changed:
infoPathFormData = ms.GetBuffer();
to
infoPathFormData = ms.ToArray();
All done! Now we have the equivalent of a poor man’s InfoPath form server. As my wife often reminds me, I am still a programmer at the core…