function XDocument::OnSubmitRequest(eventObj)
{
// If the submit operation is successful, set
// eventObj.ReturnStatus = true.
var fSuccessful = false;
// 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;
}
}
{
// If the submit operation is successful, set
// eventObj.ReturnStatus = true.
var fSuccessful = false;
// 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;
}
}
博客展示了一个名为OnSubmitRequest的函数,用于在Windows SharePoint Services文档库中提交文件。函数会先检查文件是否存在,若不存在则提交;若要替换原文件,需先删除。通过XMLHTTP对象进行操作,根据不同状态码判断操作是否成功。
343

被折叠的 条评论
为什么被折叠?



