how to access to a windows share with credential (VB.NET)?

alessandro belli 131 Reputation points

I need to access from my code in (framework 4.5) to a network smb share on an external domain that require authentication with windows credential.
I've tryed with a code like this
Dim theNetworkCredential = New System.Net.NetworkCredential(My.Settings.username, My.Settings.password)

        Dim theNetcache = New CredentialCache

        Dim urx As New Uri("\\\myshare")

        theNetcache.Add(urx, "Basic", theNetworkCredential)

        Dim theFolders() As String = System.IO.Directory.GetDirectories(My.Settings.share)

but It fail with "unknow user or wrong password"
Any Idea?
Thank you

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,135 questions
{count} votes