May 24, 2013 at 3:51 am
Hi All,
Just like to share a piece of code, where the requirement was to copy a excel file from share point link using script task.Here the share point link uses "NTLM" type authorization .
I have used webclient object to copy the file to local windows folder.
Dim file As FileInfo = New FileInfo("your local folder with file name appended")
ServicePointManager.ServerCertificateValidationCallback _
= New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack)
Dim myCredentialCache As System.Net.CredentialCache = New System.Net.CredentialCache
myCredentialCache.Add(New System.Uri("share point link with excel file"), "NTLM", New System.Net.NetworkCredential("username", "password", "domain"))
' download the file from SharePoint or Archive file system to local folder
Dim client As New WebClient()
client.Credentials = myCredentialCache
client.DownloadFile(New System.Uri("share point link with excel file"), file.FullName)
Function CertificateValidationCallBack(ByVal sender As Object _
, ByVal certificate As X509Certificate _
, ByVal chain As X509Chain _
, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
Return True
End Function
i have to use this function CertificateValidationCallBack, which resolved 401 unauthorized error issue.
Let me know your comments.
Viewing post 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply