The form I'm working with is a timesheet. The employee submits it to a "supervisor" library. The supervisor will open the form, digitally sign it, then submit it to a "payroll" library. At this point I need the copy in the supervisor library to be deleted. The problem I have is it returns "Access is denied". I think the problem is the form has not completely closed by the time the delete is called and it thinks the file is still in use. I know the code works because if I tell it to delete a file I'm not currently in it works fine. It will even fail if I change "DELETE" to "GET". I have checked the path that is being passed and I have checked permissions. Maybe someone can tell me where I've gone wrong. What's really strange is if I skip the submit and go straight to the delete it works fine! I'm using 2003. Here's the functions I have:
private sub DeleteXmlDoc(strUrl)
' Create the XMLHTTP object
dim objXmlHttp
set objXmlHttp = CreateObject("MSXML2.XMLHTTP.5.0")
' ######## THIS IS WHERE IT FAILS #########
objXmlHttp.Open "DELETE", strUrl, false
objXmlHttp.send
set objXmlHttp = nothing
end sub
private function SubmitXmlDoc(strUrl)
dim fFileExists
fFileExists = false
dim blnSubmitSuccess
blnSubmitSuccess = false
' Create an XMLHTTP object to transport the file.
dim objXmlHttp
set objXmlHttp = CreateObject("MSXML2.XMLHTTP.5.0")
' Attempt to open to the form location to check if a form with the same name already exists
objXmlHttp.Open "GET", strUrl, false
objXmlHttp.Send
' Status 200 or 201 = file exists
' This should never happen because the file name is time stamped to be unique
if objXmlHttp.status = 200 or objXmlHttp.status = 201 then
fFileExists = true
XDocument.UI.Alert("Submit failed. The file already exists.")
end if
' If no form at the same URL has been found, proceed to submit.
if objXmlHttp.Status = 404 or not fFileExists then
'Submit the form to the form library.
objXmlHttp.Open "PUT", strUrl, false
objXmlHttp.Send XDocument.DOM.xml
' Status codes of 200 or 201 indicate that the form
' has been submitted successfully.
if objXmlHttp.Status = 200 or objXmlHttp.Status = 201 then
blnSubmitSuccess = true
end if
end if
set objXmlHttp = nothing
SubmitXmlDoc = blnSubmitSuccess
end function
private sub CTRL445_5_OnClick(eventObj)
dim strUrl
strUrl = "http://mysharepointsite/formlibrary/formname.xml"
' Try the submit
if submitxmldoc(strUrl) then
dim curDocUrl
curDocUrl = XDocument.URI
' Close the file
XDocument.View.Window.Close(true)
' Delete the old file
DeleteXmlDoc(curDocUrl)
end if
end sub