Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / December 2005

Tip: Looking for answers? Try searching our database.

Programmatically create InfoPath documents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 29 Dec 2005 21:00 GMT
I am collecting data though a C# program and I would like to be able to
programmatically create an InfoPath form.   I found a way to do it in JScript
by using an ActiveXObject  like this ...  

var oApp = new ActiveXObject("InfoPath.Application");
var oXDocument =
oXDocumentCollection.NewFromSolution("http://server/sites/MySite/PurchaseOrder/Forms/template.xsn");
oXDocument.DOM.selectSingleNode("//ID").text = "something";

I would like to be able to do all of that but in C#

Does anyone know a way that doesn't Involve downloading the xsn file
unpacking it in order to get the template.xml file out?

I have tried both of these dlls with no luck.

Microsoft.Office.Interop.InfoPath.SemiTrust.dll
Microsoft.Office.Interop.InfoPath.dll

Thanks,

 Andrew
Boris Kleynbok - 29 Dec 2005 21:25 GMT
You can generate form XML template by opening xsn then saving blank form.
Then you can load that up as XmlDocument and work with XmlDocument by
accessing elements using a combination of DOM and XPath and populate InnerXml
or InnerText from whatever datasources you choose. I am working  with
Strongly Typed Datasets in VS2005.

Quick sample on how you can load XML from file into XmlDocument
xml_string is the location of your file:

XmlTextReader xtr = new XmlTextReader(new StringReader(xml_string));
               xtr.Read();
               xmlDocument.Load(xtr);

This is how you could access the Xml elements:
XmlNodeList lisp = doc.GetElementsByTagName("mstns:LisPendantsList");

this would get you the top complex type elements and by accessing and
scrolling through XmlNodeList you can access InnerXml or InnerText property.

Loading blank form will save you the hassle in dealing with namespaces.

Hope this helps.
Signature

Boris Kleynbok
Web Developer
DotComFactory

> I am collecting data though a C# program and I would like to be able to
> programmatically create an InfoPath form.   I found a way to do it in JScript
[quoted text clipped - 18 lines]
>
>   Andrew
Andrew - 30 Dec 2005 14:20 GMT
 The only fear I have in doing that is if the user drammically changes the
xsn form without saving a new xml template or really if they change anything
at all since the namespace will be different now between the template xml
file and the XSN file.

NameSpace manager isn't all that bad.  Since I really knew nothing about
XML before InfoPath it did take a little bit, but here is some code for
getting the namespace manager and prefix out of the InfoPath xml doc.  It's
in C#

#region Get name space
public XmlNamespaceManager GetNamespaces(XmlDocument xmlDoc)
    {
     XmlNode node1 = xmlDoc.DocumentElement;
                 XmlNamespaceManager manager1 = new
XmlNamespaceManager(xmlDoc.NameTable);
    int num1 = 4;
    XmlNode node2 = node1.Attributes.Item(num1);
    string text1 = node2.LocalName;
    string text2 = node1.Attributes.Item(num1).Value;
    manager1.AddNamespace(text1,text2);
    return manager1;
               }
#endregion

Thanks,

Andrew

> You can generate form XML template by opening xsn then saving blank form.
> Then you can load that up as XmlDocument and work with XmlDocument by
[quoted text clipped - 41 lines]
> >
> >   Andrew

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.