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;
}
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;
}