继这项出色的工作之后,请点击此处: 将文件批量复制到 SharePoint 网站
我现在可以通过单击按钮将我的压缩文件上传到 Sharepoint。
我现在的问题是:如何删除使用相同方法上传的文件?
我稍微修改了代码以将不同的文件保存到不同的 SharePoint 文件夹。下面的示例:
Public Sub CopyToSharePoint()
Dim xmlhttp
Dim sharepointUrl
Dim sharepointFolder
Dim sharepointFileName
Dim LstrFileName, strFilePath, strMonthYear, PstrFullfileName, PstrTargetURL As String
Dim LlFileLength As Long
Dim Lvarbin() As Byte
Dim LvarBinData As Variant
Dim fso, LobjXML As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fldr As folder
Dim f As File
'Parent Sharepoint
sharepointUrl = "[SHAREPOINT PATH HERE]"
'Sets the Month%20Year
strMonthYear = Format(Now(), "mmmm yyyy") & "\"
'File Path
strFilePath = "[ARCHIVE DRIVE]" & strMonthYear
'Check to see if DRA for current month%20year exists
If Len(Dir(strFilePath, vbDirectory)) = 0 Then
MkDir "strFilePath"
End If
Set LobjXML = CreateObject("Microsoft.XMLHTTP")
'Where we're uploading files from
Set fldr = fso.GetFolder(strFilePath)
For Each f In fldr.Files
If Format(f.DateCreated, "dd/mm/yyyy") = Format(Now(), "dd/mm/yyyy") Then
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
' Send the file in.
LobjXML.Send LvarBinData
End If
NextF:
Next f
Set LobjXML = Nothing
Set fso = Nothing
End Sub