getting data from another server

eric13

Active member
Joined
May 25, 2006
Messages
30
Programming Experience
3-5
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

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]
 
More information,

This code works when i run it on my local host, when i move it to our web server it does not work.

Also, it doesn't seem like it's using the given credentials at all, i purposely put in a bad login and it still worked on my local host. Is there something I have to configure on the web server or in my web.config file to allow it to use the networkcredentials provided to the webclient object?
 
Back
Top