删除使用XMLHTTP SharePoint文件(Deleting Sharepoint Files

2019-09-24 06:58发布

从这个优秀的作品,在这里的继: 批处理文件拷贝到SharePoint网站

我现在可以上传我的压缩文件有一个按钮的点击到SharePoint。

我现在的问题是这样的:我如何删除我上传使用同样的方法把文件?

我已经修改了代码稍有保存不同的文件,以不同的SharePoint文件夹。 示例如下:

 Public Sub CopyToSharePoint() 

暗淡XMLHTTP昏暗sharepointUrl昏暗sharepointFolder昏暗sharepointFileName昏暗LstrFileName,strFilePath,strMonthYear,PstrFullfileName,PstrTargetURL作为字符串昏暗LlFileLength只要昏暗Lvarbin()作为字节昏暗LvarBinData作为变暗淡FSO,LobjXML作为对象FSO设置=的CreateObject( “Scripting.FileSystemObject的” )昏暗FLDR作为文件夹昏暗˚F作为文件

“父的SharePoint sharepointUrl = “[SHAREPOINT PATH HERE]”

“设置月份%20Year strMonthYear =格式(现在(), “MMMM YYYY”)& “\”

“文件路径strFilePath = “[ARCHIVE DRIVE]” &strMonthYear

“检查是否为DRA当前月份%20年存在如果len(DIR(strFilePath,vbDirectory))= 0那么MKDIR “strFilePath” END IF

设置LobjXML =的CreateObject( “Microsoft.XMLHTTP”)

“当我们从上传设置FLDR = fso.GetFolder文件(strFilePath)

按照每个F在fldr.Files

如果格式(f.DateCreated, “日/月/年”)=格式(现在(), “日/月/年”)。然后

 If InStr(1, f.Name, "[FILESTRING1]", vbTextCompare) > 0 Then sharepointFolder = "[SHAREPOINTSTRING1]/" ElseIf InStr(1, f.Name, "[FILESTRING2]", vbTextCompare) > 0 Then sharepointFolder = "[SHAREPOINTSTRING2]" ElseIf InStr(1, f.Name, "[DONOTUPLOADTHISFILE]", vbTextCompare) > 0 Then GoTo NextF: Else sharepointFolder = "[SHAREPOINTMAINFOLDER]" End If 

sharepointFileName = sharepointUrl&sharepointFolder&f.Name

PstrFullfileName = strFilePath & f.Name
LlFileLength = FileLen(PstrFullfileName) - 1

' Read the file into a byte array.
ReDim Lvarbin(LlFileLength)
Open PstrFullfileName For Binary As #1
Get #1, , Lvarbin
Close #1

' Convert to variant to PUT.
LvarBinData = Lvarbin
PstrTargetURL = sharepointUrl & sharepointFolder & f.Name

' Put the data to the server, false means synchronous.
LobjXML.Open "PUT", PstrTargetURL, False

“发送的文件中。LobjXML.Send LvarBinData

万一

NextF:接下来˚F

设置LobjXML =什么FSO设置=什么

结束小组

Answer 1:

我没有关闭请求到服务器,D'哦! 在一个单独的实例设置它解决了这个问题对我来说。

我没有文件名转换为二进制文件,然后变体,仅仅保持它作为一个字符串。 你必须忽略NOTHING从最后LobjXML.SEND在LastCoder的例子给出。 添加这再现了运行时错误我上面给的。

感谢您的帮助,LastCoder。 下面是修改后的代码:


Public Sub DeleteFromSharePoint()

Dim xmlhttp
Dim sharepointUrl, sharepointFolder, sharepointFileName
Dim f, strZip As String
Dim LobjXML As Object

' Parent Sharepoint
sharepointUrl = "[SHAREPOINT URL]"

' In this test module, we're just deleting from the parent directory
sharepointFolder = ""

' Sets the report name we want to remove
f = "test"

' Sets the full .ZIP filename
' This is how reports are archived by date
strZip = f & "%20-%20" & Format(Now() - 1, "YYYY.MM.DD") & ".zip"

Set LobjXML = CreateObject("Microsoft.XMLHTTP")

    sharepointFileName = sharepointUrl & sharepointFolder & strZip

    ' Removes the data from the server, false means synchronous
    LobjXML.Open "DELETE", sharepointFileName, False

    ' Sends the request to remove the file
    LobjXML.Send

  Set LobjXML = Nothing

End Sub


文章来源: Deleting Sharepoint Files using XMLHTTP