programmatically modify a form and save it as a new instance

G

g.cacciapaglia

I want to know if it is possible to create programatically a new form
starting from a "template" form already published in a form library in
sharepoint. What I want to do is modify the form (respecting the
underlying xsd schema) e save it as a new instance in the same form
library. All of these tasks should be performed server side.


Thanks in advance for any answer,
Giuseppe.
 
K

Kevin Changet

Yes, this is possible. I currently am doing this very thing.

We have 2 scenarios
1) We check to see if the form has been acted on in the past 24 hours
(modified date) and is currently in Open status. If so, we open the form,
modify a field and resave the form up to SharePoint. A subsequent process
emails users that forms XY & Z have not been worked.

2) We have a form that is normally filled out by an end-user, but can be
"auto-generated" by a different system. This one uses a blank template and
fills in the appropriate information prior to saving it. It can then be
opened by the manager via IP later.

In scenario 2, something to consider though is that if you re-publish the
form, you will also need to put out the new template to the server side app
modifying the IP files. There is a way to extract the template from the
*.XSN file (since it's just really a CAB file), and then use that in our
server process, but we haven't gotten there yet.

Basically, you create a console app that slurps in the XML file, makes the
changes, and then saves the file back to wherever you want. Provided that
you use the same header information, all is good. Problems arise when the
schema changes and you don't update the template file.

Hope this helps.
 
J

Jim

Kevin,

It seems you have solved the problem for the preceding post too!

Could you provide more specifics on retrieving the file from Sharepoint and
then saving it back to Shrepoint? This would be greatly appreciated.

Thanks,

Jim
 
K

Kevin Changet

The way I do it, is to create a Visual Studio Console Application.
I do my development on a SP Development server, however if you do it
elsewhere you'll need to copy the DLL and install it into your GAC.
Reference the Microsoft.SharePoint.dll in the project
Reference System.XML
Add a "Using Microsoft.SharePoint" at the begining.
Add a "Using System.XML"
Now you'll have access to the necessary methods to start building.

Using SPList, SPWeb, SPSite methods access the SP document library you want
and then open a copy of the XML file.

Modify the needed nodes utilizing the XML methods

Save the file back up to SP using the SPList, SPWeb, and SPSite methods.

That's it!

If you search on the Intranet for some of these keywords, I'm sure you'll
come across something that will suit your needs or at least get you close to
what you need. There are plenty of examples out there. It will probably be
more in-depth and more useful than this post.

Good luck!
 
J

Jim

Thank You! That's the missing piece! I'm not on a SP Server but I now know
the bits I need to install!
 

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