Following on from this excellent piece of work, here: Batch copy files to SharePoint site
I can now upload my zipped files to Sharepoint with a click of a button.
My problem is now thus: How do I delete the files I upload using the same method?
I've amended the code slightly to save different files to different SharePoint folders. Sample below:
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