この優れた作業に続いて、こちら: SharePoint サイトへのファイルのバッチ コピー
ボタンをクリックするだけで、zip ファイルを 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