从密码保护的网站通过Windows安全VBA / .NET下载文件 [英] VBA / .Net download files from password protected website via Windows Security

查看:172
本文介绍了从密码保护的网站通过Windows安全VBA / .NET下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SharePoint测试网站(Azure的SharePoint场),其中包含多个图像文件和一些文档模板。我想将图像下载到本地驱动器。我期待着通过URL列表循环,例如 HTTP://mySharePointSite/Sites/Images/Image01.png 并下载每个反过来。我试过URLDownloadToFile如果我把图像在一个正规的网站,但我不能让过去的Windows安全性,这种方法伟大的工程。

I have a SharePoint test website (Azure SharePoint farm) which contains several image files and some document templates. I want to download the images to my local drive. I anticipate looping through a list of URLs, e.g. http://mySharePointSite/Sites/Images/Image01.png and downloading each in turn. I've tried URLDownloadToFile which works great if I put the images on a regular website but I'm unable to get past Windows Security with this approach.

我在创建InternetExplorer.Application对象(后期绑定),并可以查看我的图片,但我无法下载他们有一展身手。试图ieApp.ExecWB但这会引发似乎不可逾越的运行时间错误。

I had a go at creating an InternetExplorer.Application Object (late binding) and can view my images but am unable to download them. Was trying ieApp.ExecWB but this throws a Run Time Error that seems insurmountable.

我也试过WinHTTP.WinHTT prequest.5.1(计算器22051960 ),但是,而看起来前途无量它返回一个简短的字符串???????代替图像。

I've also tried WinHTTP.WinHTTPrequest.5.1 (StackOverflow 22051960) but, while that looked promising it returned a short string "???????" instead of an image.

我真的希望有一个VBA的解决方案,我想知道,如果模拟用户可以提供选择,或者有其他的选择(使用的SendKeys不含)。可悲的是我推着我的VBA知识的限制和真的可以使用一些指导。

I'm really hoping for a VBA solution and am wondering if Impersonate User might provide options, or if there are other options (excluding using SendKeys). Sadly I'm pushing the limits of my VBA knowledge and could really use some guidance.

是否有可能从共享点从VBA下载?结果
如果是的话怎么样,我失去了一些东西简单?

Is it possible to download from share point from VBA?
If so how, am I missing something simple?

我可以粘贴code,但我真的不知道我有什么值得分享。如果这是不可能的或不可靠的VBA那么将有可能VB.Net(我的下一个陡峭的学习曲线)?

I can paste code, but really I'm not sure I have anything worth sharing. If this is not possible or unreliable in VBA then would be possible with VB.Net (my next steepest learning curve)?

推荐答案

希望这可以帮助别人。最后我用Visual Studio创建在VB.Net一个DLL,我可以从VBA调用。 VB.Net DLL要求microsoft.sharepoint.client引用

Hope this helps someone. I ended up using Visual Studio to create a dll in VB.Net that I can call from VBA. VB.Net dll requires references to microsoft.sharepoint.client

和VBA的code要求所得到的DLL的引用。

And the VBA code requires a reference to the resulting 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

这篇关于从密码保护的网站通过Windows安全VBA / .NET下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆