VB6:从Sharepoint 365下载文件

时间:2017-07-28 15:06:32

标签: sharepoint https download vb6 office365

我的工作刚刚将我们从Sharepoint 2010迁移到Sharepoint 365.我已经制作了许多直接从Sharepoint目录下载文件的工具。显然我的下载代码(以及下载在线文件的任何其他代码)不再有效。这是我过去使用过的代码:

Function Download_File(ByVal vWebFile As String, ByVal vLocalFile As String, lFilesize As Long) As Boolean
'   Code taken from: http://stackoverflow.com/questions/12815142/vba-download-and-save-in-c-user
'   on 2013-06-19
    Dim strHeader As Variant
    Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte

    On Error Resume Next

Debug.Print "Download_File: Stage 1"
    'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP"): Me.Repaint: Debug.Print Time$: DoEvents
    oXMLHTTP.Open "GET", vWebFile, False: Me.Repaint: Debug.Print Time$: DoEvents 'Open socket to get the website
    oXMLHTTP.sEnd: Me.Repaint: Debug.Print Time$: DoEvents 'send request

Debug.Print "Download_File: Stage 2"
    'Wait for request to finish
    Do While oXMLHTTP.readyState <> 4
        DoEvents
    Loop

Debug.Print "Download_File: Stage 3"
    strHeader = oXMLHTTP.getAllResponseHeaders
    If InStr(1, strHeader, "Content-Length:") > 1 Then
        lFilesize = CLng(Mid(strHeader, InStr(1, strHeader, "Content-Length:") + 16, InStr(1, strHeader, "Content-Type:") - (InStr(1, strHeader, "Content-Length:") + 16)))
    End If

Debug.Print "Download_File: Stage 4"
    oResp = oXMLHTTP.responseBody 'Returns the results as a byte array

Debug.Print "Download_File: Stage 5"
    'Create local file and save results to it
    vFF = FreeFile
    If Dir(vLocalFile) <> "" Then Kill vLocalFile
    Open vLocalFile For Binary As #vFF
    Put #vFF, , oResp
    Close #vFF

Debug.Print "Download_File: Stage 6"
    'Clear memory
    Set oXMLHTTP = Nothing

Debug.Print "Download_File: Stage End"

End Function

问题是我可以下载一个文件,它的大小不合适。也许它只是一个具有正确文件名的容器?一个可能的问题是,我们现在正在使用安全HTTP,而它是标准HTTP之前。

使用Sharepoint提供的“下载链接”也不起作用。这是365问题还是https问题?

谢谢!

0 个答案:

没有答案