Automate .xml Form Creation in VB.NET

M

Michael Reyeros

Can a .xml infopath form be created from an .xsn template file and
automatically saved to a document library all through vb.net code without
having to open InfoPath application???
 
M

Michelle Beall

Yes but not exactly.
If you need a user to enter data into the form then most definitely no. The
user will need to have InfoPath to interact with the form and enter data.

The reason I say yes but not exactly is that you can (in theory) do the
following, but I haven't tried it:
(1) create the infopath form
(2) save a blank xml file by filling out the form but not entering any data.
(3) create a .NET application that uses the XML file generated as a
template. Here you can manipulate the XML file just as you would any other
by setting node values
(4) Use Sharepoint's webservices to save the XML document to the document
library.

Hope that gives you some ideas. Let me know if you get it working.

Michelle
 
M

Michael Reyeros

Well lets say I create the actual .xsm form template locally on my computer
then I upload it to the main forms library. So the .xsn template exists.
All I want is to be able to create the empty xml file and have it stored in
another document library.
 
M

Michelle Beall

The original problem you stated was you don't want to open InfoPath and you
want to store an empty xml file in another document library (possibly in a
different site or on a different server). Maybe if you explain the context a
little it might shed a little more light on what/why you're trying to do.

When you publish the template the Sharepoint the xsn file is located in a
folder under the form library with the name "template.xsn" as follows:
<formlibrary>/forms/template.xsn. When you "fill out the form" the xml
document is generated by InfoPath using the schema and the transformations in
the template. So you either have to open the form in InfoPath and then
automate the saving and closing of the form or do something along the lines
of what I suggested before. If you have any logic inside the infopath form
that needs to be run (such as in the onload) then you must open the template
using InfoPath.

You can open the InfoPath template to fill out the form without having to go
the form library. Just add a hyperlink to your webpart/webform with the href
pointing to the complete URL of the template. (don't forget to add
/forms/template.xsn to the end of the form library url). However, this still
opens InfoPath.

If you know the location of the document library and it is unchanging you
can set the save location in code in the form template. Look at
thisXDocument.UI.SetSaveAsDialogLocation()
The following MSFT article may help you out a little:
http://msdn.microsoft.com/library/d...dc_ip2003_ta/html/odc_InfoPath_extending_save
 
M

Michael Reyeros

Ok, sorry for not explaining thoroughly what I am trying to do.

This is my situation. I have a main document library that holds .xsn form
templates. I also have subsites that each have their own document
libraries. (Also just so you have a better understanding I am using a
custom interface of plain aspx pages, I am not using hte sharepoint
interface to access the sharepoint info.)

So What i have done is created a treeview of the documents that are in my
main document library that can be accessed from all other document
libraries. The user can see the name of the documents in the treeview
control and can click on the document to open the file. At the moment if th
user click on the filename the appropriate program is opened with the
current file ready for edit. If it is an .xsn template file infopath is
opened and the user can fill out the form template and save to the current
library that they are in. But what I want to do is if the user clicks on a
..xsn form template I want that before Infopath is opened for the application
to create the empty xml document with a specific name and save it to the
current document library and then open that newly created .xml document so
that the user can fill it out and simply hit save and have it save to
document library.

I hope that this is a better explanation then the one originally supplied.
 
M

Michelle Beall

ahhhh ... ok.
Why the step of saving the blank xml in the document library? Why can't the
user just have infopath open and enter data then click on save and have the
completed xml form saved? That would make *your* task easier.

You can set the save location by using the SetSaveAsDialogLocation() I
mentioned earlier. This sets the default save location. You can also use
SetSaveAsDialogFileName() to set the default file name when the user clicks
on save.

What happens in your scenario if a user would click on the infopath template
to create a new document and then decide to abandon that document. Maybe
they clicked on it by accident.
 

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