Help with saving xml form in a document library

M

Michael Reyeros

I am trying to give the user the ability to choose a form template and have
it save it to another document library. I found the folowing piece of code
from msdn and I tried adding it to the onload even of the form and it did
what I wanted it to do except that I had to hard code the URL of the
destination document library. I want to be able to have this be dynamic so
that the user can specify the document library as well as not have to have
infopath open at all simply have this task automated programmatically. Here
is the code sample:


// Set the URL of the file that you want to submit here.
var strUrl =
"http://ServerName/SiteName/DocumentLibraryName/testform.xml";

try
{
// Create an xmlhttp object.
var oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");

// See whether the document with the same name already exists in the
Windows SharePoint Services (WSS) document library.
oXmlHttp.Open("HEAD", strUrl, false);
oXmlHttp.Send();

// No document with the URL has been found. Continue to submit.
// If you must replace the original file, you must call
// oXmlHttp.Open("DELETE", strUrl, false) to delete the document
// in the WSS document library.
if (oXmlHttp.Status == 404)
{
// Put the document in the WSS document library.
oXmlHttp.Open("PUT", strUrl, false);
oXmlHttp.Send(XDocument.DOM.xml);

// A 200 status code or a 201 status code indicates that the
form has been submitted successfully.
if (oXmlHttp.Status == 200 || oXmlHttp.Status == 201)
{
fSuccessful = true;
}
}
}
catch (ex){}

if (fSuccessful)
{
XDocument.UI.Alert("Document submitted successfully.");
eventObj.ReturnStatus = true;
}
else
{
eventObj.ReturnStatus = false;
}
 
D

dbsearch04

Hey Michael:

I have been doing this much more easily. Just put this code in the
source of a Form Web part.

----------------------------------------------
<script language="javascript">
var strSavLoc = "/sites/site2/formlib1";
var strProgID = "SharePoint.OpenDocuments";
function MyFormInvoke()
{
var strTempl1 = "/sites/site2/formTemplate6.xsn";
createNewDocumentWithProgID(makeAbsUrl(strTempl1),
makeAbsUrl(strSavLoc), strProgID, false);
}
</script>
<a href="javascript:MyFormInvoke()"/>start filling out Template 6</a>
----------------------------------------------

When they hit the link, it will drive InfoPath and when they save, it
willsend them to the library you want.

HTH.

Regards..
 
M

Michael Reyeros

I believe that this function first open infopath and the user has to then
save the file right??

But is it possible to do this without opening infopath and not having to
make the user save the file manually. I want the entire process to be
automated. The only thing that I want to pass in is the URL of the template
and the URL of where I want the document to be saved and have the XML file
created without infopath opening up.
 
D

dbsearch04

I gave him a couple of other replies. Maybe he will post those out here
for other soles.

Regards..
 

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