【问题标题】:VBA / .Net download files from password protected website via Windows SecurityVBA / .Net 通过 Windows 安全从受密码保护的网站下载文件
【发布时间】:2015-09-23 04:30:23
【问题描述】:

我有一个 SharePoint 测试网站(Azure SharePoint 场),其中包含多个图像文件和一些文档模板。我想将图像下载到我的本地驱动器。我预计循环遍历 URL 列表,例如http://mySharePointSite/Sites/Images/Image01.png 并依次下载。我已经尝试过 URLDownloadToFile,如果我将图像放在常规网站上效果很好,但我无法通过这种方法通过 Windows 安全性。

我尝试创建 InternetExplorer.Application 对象(后期绑定)并且可以查看我的图像但无法下载它们。正在尝试 ieApp.ExecWB 但这会引发Run Time Error that seems insurmountable

我也尝试过 WinHTTP.WinHTTPrequest.5.1 (StackOverflow 22051960) 但是,虽然看起来很有希望,但它返回了一个短字符串“???????”而不是图像。

我真的希望有一个 VBA 解决方案,我想知道 Impersonate User 是否可以提供选项,或者是否有其他选项(不包括使用 SendKeys)。可悲的是,我正在突破我的 VBA 知识的极限,并且真的可以使用一些指导。

是否可以从 VBA 的共享点下载?
如果是这样,我是否错过了一些简单的东西?

我可以粘贴代码,但我真的不确定我有什么值得分享的。如果这在 VBA 中不可能或不可靠,那么 VB.Net 可以实现(我的下一个最陡峭的学习曲线)?

【问题讨论】:

    标签: vba excel azure sharepoint


    【解决方案1】:

    希望这对某人有所帮助。我最终使用 Visual Studio 在 VB.Net 中创建了一个可以从 VBA 调用的 dll。 VB.Net dll 需要引用 microsoft.sharepoint.client

    VBA 代码需要引用生成的 dll。

    Imports Microsoft.SharePoint.Client
    
    Module Module1
        Sub Main()
            Dim myContext As Microsoft.SharePoint.Client.ClientContext
            myContext = New ClientContext("http://TestSP-a.cloudapp.net/sites/Images/")
    
            Dim myCredentials As New System.Net.NetworkCredential
            '' I'm accessing a website from the outside so there
            '' are no credentials on my PC. If on the same NW I 
            '' assume I can use the line below instead of the 
            '' 3 lines that follow.
            'myCredentials = System.Net.CredentialCache.DefaultNetworkCredentials
            myCredentials.UserName = "UserNameForSharePoint"
            myCredentials.Password = "PassWordForSharePoint"
            myCredentials.Domain = ""   ' <-- Leave Blank
    
    
            Dim mySiteSP As New Uri("http://TestSP-a.cloudapp.net/sites/Images/Image1.png")
            Dim myTemp As String = "C:\temp\test.png"
            My.Computer.Network.DownloadFile(mySiteSP, myTemp, myCredentials, True, 600000I, False)
    
    
        End Sub
    
    End Module
    

    【讨论】:

      猜你喜欢
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-02
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多