我在 SO、SU 和SP.SE中搜索了解决方案,但找不到我需要的东西。我正在寻找可能是脚本或其他一些非编码方法/工具的解决方案。
我正在尝试编写一个脚本(供其他人使用)或某种其他形式的自动化来自动将各种报告上传到 SharePoint 网站。我已经设法使以下(VBScript)代码工作,但仅适用于基于文本的文件——在这种情况下为 .CSV,尽管这也适用于 .TXT 等。
Option Explicit
Dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
UploadAllToSP sCurPath
Sub UploadAllToSP(sFolder)
Dim fso, folder, fil
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(sFolder)
For Each fil In folder.Files
If fso.GetExtensionName(fil) = "csv" Then
UploadFileToSP fil
End If
Next
End Sub
Sub UploadFileToSP(ofile)
Dim xmlhttp
Dim sharepointUrl
Dim sharepointFileName
Dim tsIn
Dim sBody
Set tsIn = ofile.openAsTextstream
sBody = tsIn.readAll
tsIn.close
sharepointUrl = "http://SHAREPOINT URL HERE"
sharepointFileName = sharepointUrl & ofile.name
set xmlHttp = createobject("MSXML2.XMLHTTP.4.0")
xmlhttp.open "PUT", sharepointFileName, false
xmlhttp.send sBody
If xmlhttp.status < 200 Or xmlhttp.status > 201 Then
wscript.echo "There was a problem uploading " & ofile.name & "!"
End If
End Sub
这仅适用于文本文件,因为它将文本数据通过管道传输到 SP 站点上的文件中。但是,如果我想传输任何类型的二进制文件(.XLS、.PDF),这会导致上传垃圾。
我试图看一下Shell.Application
==> .Namespace()
,但这似乎不适用于 URL,而只能用于物理驱动器。这是我尝试过的其他一些内容(修剪以显示相关部分):
Set oApp = CreateObject("Shell.Application")
If oApp.NameSpace(sharepointUrl) <> Null then ' Always Null!
' Copy here
' Some lines omitted
oApp.NameSpace(sharepointUrl).CopyHere ofile.Name ' This also fails when not surrounded by the Null check
Else
MsgBox "SharePoint directory not found!"
End If
我还尝试了使用 xcopy 的批处理文件,但无法连接到http://
任何一个。我查看了这种方法,它可能对我有用,但我不想处理 mapping/ NET USE
,因为我们公司有多个网络共享,其映射取决于谁登录。
由于这些都不是我需要的方式:有没有一种方法可以自动化这种功能?
我有使用 VBA/VBscript 的经验,所以像上面这样的脚本,或者内置在 MS Office 应用程序中的东西(Outlook 是最好的,但我可能可以适应我所得到的任何东西)会更可取。话虽如此,我对任何允许我这样做的方法持开放态度,在 Windows 或 Office 中本地运行。但是,我无权访问 Visual Studio,因此无法使用任何 .NET 功能。