Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将文件批量复制到SharePoint网站_Sharepoint_Vba_File Upload_Vbscript_Automation - Fatal编程技术网

将文件批量复制到SharePoint网站

将文件批量复制到SharePoint网站,sharepoint,vba,file-upload,vbscript,automation,Sharepoint,Vba,File Upload,Vbscript,Automation,苏,我找了这么多,想找到一个解决办法,但找不到我需要的。我正在寻找一种解决方案,可能是脚本或其他一些非编码方法/工具 我正在尝试编写一个脚本(供他人使用)或其他形式的自动化,以便将各种报告自动上载到SharePoint网站。我已经设法使以下(VBScript)代码正常工作,但仅适用于基于文本的文件——在本例中为.CSV,但也适用于.TXT等 Option Explicit Dim sCurPath sCurPath = CreateObject("Scripting.FileSystemObj

苏,我找了这么多,想找到一个解决办法,但找不到我需要的。我正在寻找一种解决方案,可能是脚本或其他一些非编码方法/工具

我正在尝试编写一个脚本(供他人使用)或其他形式的自动化,以便将各种报告自动上载到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
我还尝试了使用xcopy的批处理文件,但它也无法连接到
http://
。我查看了,这可能对我有用,但我不想处理映射/
网络使用
,因为我们公司有多个网络共享,其映射因登录者而异

由于所有这些都不是我所需要的方式:有没有一种方法可以自动化此类功能?

我有使用VBA/VBscript的经验,因此最好使用上述脚本或MS Office应用程序中内置的脚本(Outlook是最好的,但我可能可以调整提供给我的任何脚本)。也就是说,我愿意接受任何允许我这样做的方法,在Windows或Office中本机运行。但是,我没有访问Visual Studio的权限,因此无法使用任何.NET功能。

感谢您为我指出了我没有看到的明显答案。张贴相关的代码,因为我不相信这还存在于如此

Sub UploadFilesToSP(sFolder)

Dim sharepointUrl
Dim sharepointFileName
Dim LlFileLength
Dim Lvarbin()
Dim LobjXML
Dim LvarBinData
Dim PstrFullfileName
Dim PstrTargetURL
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fldr
Dim f

    'This has not been successfully tested using an "https" connection.
    sharepointUrl = "http://SHAREPOINT URL HERE"
    Set LobjXML = CreateObject("Microsoft.XMLHTTP")
    Set fldr = fso.GetFolder(sFolder)

    For Each f In fldr.Files
        sharepointFileName = sharepointUrl & f.Name

        PstrFullfileName = sFolder & 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 = sharepointFileName 

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

        ' Send the file in.
        LobjXML.Send LvarBinData
    Next f

Set LobjXML = Nothing
Set fso = Nothing

End Sub
这是VBA代码,格式化后主要用于VBScript,尽管我无法正确传输此块。作为VBA,这可以通过指定数据类型等进行改进

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

这是一个非常古老的帖子,但是非常有用,所以感谢大家的贡献。这是我的早期绑定版本。我发现之前的帖子不起作用,因为VBA假设并没有声明变量类型

Private Sub-cmduploadtoapplications和approvals\u Click()
作为字符串的Dim strSharePointUrl
Dim strSharePointFileName作为字符串
尺寸LNGFILE长度与长度相同
Dim bytBinary()作为字节
Dim objXML作为XMLHTTP
Dim varBinData作为变体
将strFullfileName设置为字符串
将strTargetURL设置为字符串
将fso设置为文件系统对象
Set fso=新文件系统对象
将文件夹设置为文件夹
将文件设置为文件
作为字符串的Dim strFolder
strFolder=CurrentProject.Path&“\Upload\”
'这尚未使用“https”连接成功测试。
strSharePointUrl=”http://sps.mysite.ca/subsite/DocLib/"
设置objXML=New-XMLHTTP'CreateObject(“Microsoft.XMLHTTP”)
Set folder=fso.GetFolder(strFolder)
对于文件夹.Files中的每个文件
strSharePointFileName=strSharePointUrl&file.Name
strFullfileName=strFolder&file.Name
lngFileLength=FileLen(strFullfileName)-1
'将文件读入字节数组。
ReDim bytBinary(lngFileLength)
将二进制文件的strFullfileName作为#1打开
得到#1,顺便说一句
关闭#1
'转换为变量以放置。
varBinData=bytBinary
strTargetURL=strSharePointFileName
'将数据放入服务器,false表示同步。
objXML.Open“PUT”,strTargetURL,False
'将文件发送进来。
发送varBinData
'现在更新元数据
下一个文件
“清理
设置objXML=Nothing
设置fso=无
MsgBox“完成”

End Sub
在google上使用
上传sharepoint vba
来查找以下内容:@Seanchisher我已经看到了,但答案的细节包括创建一个C#类。正如我在Q中指出的,我没有访问Visual Studio的权限,因此据我所知,无法使用此选项。请向下查看页面,查看dg_moore的回答,我现在看到了。:-/很抱歉查看该选项。@bill我在代码中更新了一条注释。这可能有效,也可能无效。我自己尝试过,只是简单地将
http
更改为
https
,但它只是将我的系统挂起在
LobjXML.Send LvarBinData
' Read the file into a byte array.
ReDim Lvarbin(LlFileLength)
Open PstrFullfileName For Binary As #1
Get #1, , Lvarbin
Close #1