Creating an InfoPath form in code

R

Richard Carr

Hello,

we have a customer with a web-based form that is completed by external
users.

We have a similar form (same data) for internal use created in InfoPath
2007.

What we want to do is allow the web user to complete the web-based form and
have the input converted to the InfoPath form equivalent and stored in a
forms library in MOSS 2007. The internal users would then be able to open
this form from the library in InfoPath and SharePoint Workflow would execute
according to the web user's entries.

Does anyone know how to use this?
 
W

Wozza

I havent stored infopath document in MOSS 2007, but i have created XML
documents from a web service that can be edited in infopath. I think you
should be able to get a fair way along the path by following something
similar to what I did:

1. Create an XSD that defines the structure of your data.
2. Save the contents of the Web-page based data into an xml document that
can be successfully validated against the XSD. You must add some processing
instructions and namespaces that InfoPath expects (and uses to recognize the
document). in my case this involved adding a file based url to the installed
InfoPath form. I suspect you may need to add a http url to reference the
relevant MOSS 2007 library.
3. Save the xml document in your MOSS library ....

Since i haven't done this there may be some stuff missing but hopefully this
helps.
cheers
Wozza

The C# code i used to add processing instructions:
#region AddProcessingInstructions
/*
<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution solutionVersion="1.0.0.4"
productVersion="12.0.0" PIVersion="1.0.0.0"
href="file:///P:\Projects\InfoPath%20Projects\XMLfromSQL\Publish\XMLfromSQL.xsn"
language="en-gb" ?>
<?mso-application progid="InfoPath.Document"
versionProgid="InfoPath.Document.2"?>
*/
string xsnFileName = Settings.Default.XsnFileName; // this is
currently
file:///P:\Projects\LinkUpV2\Build\Achilles.LinkUpV2.Audit.Build\Publish\ProofProtocolAuditQuestionnaire.xsn
XmlProcessingInstruction xp;
xp = xd.CreateProcessingInstruction(@"xml",
String.Format(@"version=""1.0"" encoding=""UTF-8"""));
xd.AppendChild(xp);
xp = xd.CreateProcessingInstruction(@"mso-infoPathSolution",
String.Format(@"solutionVersion=""1.0.0.4"" productVersion=""12.0.0""
PIVersion=""1.0.0.0"" href=""{0}"" language=""en-gb""", xsnFileName));
xd.AppendChild(xp);
xp = xd.CreateProcessingInstruction(@"mso-application",
String.Format(@"progid=""InfoPath.Document""
versionProgid=""InfoPath.Document.2"""));
xd.AppendChild(xp);
#endregion AddProcessingInstructions

The namespaces you need to add will probably be:
#region AddNamespaceAttributes
/*
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xmlns:ns1="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-30T11:27:35"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
*/
XmlAttribute xa;
xa = xd.CreateAttribute(@"xmlns", @"xd",
"http://www.w3.org/2000/xmlns/");
xa.InnerText =
@"http://schemas.microsoft.com/office/infopath/2003/";
xnProtocol.Attributes.Append(xa);
xa = xd.CreateAttribute(@"xmlns", @"nsl",
"http://www.w3.org/2000/xmlns/");
xa.InnerText =
@"http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-30T11:27:35/";
xnProtocol.Attributes.Append(xa);
xa = xd.CreateAttribute(@"xmlns", @"xsi",
"http://www.w3.org/2000/xmlns/");
xa.InnerText = @"http://www.w3.org/2001/XMLSchema-instance/";
xnProtocol.Attributes.Append(xa);
#endregion AddNamespaceAttributes
 
C

Clive Glover

There is a more bone headed method which works for me. First, create an xml
form from your template, then open it in a text editor. You can then create
a Sub to build up your form using string concatenatation and a dataset /
access dataconnnection / whatever to fill in the values. I save this to the
file system and open it via an aspx web page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top