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 to create an InfoPath form from c# code. So I use xsd.exe to create c# objects and XmlSerializer to compose xml files.

Also I must define "mso-application" like "progid="InfoPath.Document" versionProgid="InfoPath.Document.3" (for sharepoint 2010) and "mso-infoPathSolution". I have problem with "mso-infoPathSolution" where I must define right "name" and "solutionVersion".

I can get right name of InfoPath form by next code:

FormsService service = SPFarm.Local.GetChild<FormsService>();
service.FormTemplates["..."].Name

but I can't find any solution for "solutionVersion" of Infopath form.

How I can get "solutionVersion" for InfoPath form that was published on SharePoint?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I don't believe these make it into the file when using xsd.exe because they are processing instructions, not actually part of the XML data structure. If you need these then update the file as XML and use XPath queries such as:

var ipsNode = xml.SelectSingleNode(
    "//processing-instruction('mso-infoPathSolution')",
    namespaceManager);
ipsNode.InnerText = "TODO";

I've been down the path of using xsd.exe but try to avoid it now and create my own entity classes. The XML template is stored within the form .xsn which can be extracted like a CAB file. This can be populated with XPath queries (and vice versa to read back). While it's more work up front, once done it is much easier to work with form data:

  • XPath queries can be written to be more flexible and resistant to changes in form structure
  • when problems occur they are easier to debug
  • working with your own code rather than something auto-generated
  • gives you more flexibility, e.g. able to set and extract processing instructions as part of reading the form
  • gives you entities that are not tied to being a particular type such as dataset

Something to consider.

share|improve this answer

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.