I am trying to get a file from another server using network credentials. The login that i am using has rights to the file location.
I keep getting Access to the path '\\server\share\folder\document.pdf' is denied.
I'm not sure what i am doing wrong, my code is below
I keep getting Access to the path '\\server\share\folder\document.pdf' is denied.
I'm not sure what i am doing wrong, my code is below
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strFilePath [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].treeViewEmplWorld.SelectedNode.Value[/SIZE]
[SIZE=2]strFilePath = "[/SIZE][SIZE=2][COLOR=#800000][URL="file://\\server\share\folder\document.pdf"]\\server\share\folder\document.pdf[/URL]"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Using[/COLOR][/SIZE][SIZE=2] wc [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Net.WebClient()[/SIZE]
[SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] myCache [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Net.CredentialCache()[/SIZE]
[SIZE=2] myCache.Add([/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Uri(strFilePath), [/SIZE][SIZE=2][COLOR=#800000]"Basic"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Net.NetworkCredential([/SIZE][SIZE=2][COLOR=#800000]"login"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"password"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"domain"[/COLOR][/SIZE][SIZE=2]))[/SIZE]
[SIZE=2] wc.Credentials = myCache[/SIZE]
[SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] results [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2] results = Encoding.UTF8.GetString(wc.DownloadData(strFilePath))[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Using[/COLOR][/SIZE]