Hi Trent,

Just playing with anonymous access now for our public sites. I could be wrong 
but...I believe that if you're trying to allow access to content on a site 
requiring authentication then you will still need to allow anonymous access 
"Lists and Libraries" for the site collection. ...which probably means having 
to do it at the web app level first.

From: [email protected] [mailto:[email protected]] On Behalf Of 
Trent Allday
Sent: Monday, 7 December 2009 3:13 PM
To: [email protected]
Subject: Help! - webclient.downloadData

Hi All,

I am becoming frustrated after spending too much on this simple issue, hope you 
can help.
I have the following code to download images stored in a sharepoint document 
library behind a windows authenticated site.


Protected Function downloadImage(ByVal imageUrl As String)

         Dim filename As String = String.Empty
        Try

            Dim fileReader As New WebClient()
            fileReader.Credentials = New Net.NetworkCredential(WsUserName, 
WsPassword,wsDomain)
            filename = imageUrl.Substring(imageUrl.LastIndexOf("/") + 1)

            Return fileReader.DownloadData(imageUrl)

        Catch ex As Exception
            HttpContext.Current.Response.Write(ex.Message +"<BR>"+ 
ex.stacktrace+" <BR>" +filename)
            Return Nothing
        End Try

    End Function

Used like this: <img 
src='http://siteUrl.com/_layouts/imgResize.aspx?image=http://siteUrl.com/members/PublishingImages/bball.jpg&size=80'>


Error:
The remote server returned an error: (401) Unauthorized.
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) 
at System.Net.WebClient.DownloadData(Uri address) at 
imgResize.downloadImage(String imageUrl)
bball.jpg
Buffer cannot be null. Parameter name: buffer

The creditials are public variables and are 100% correct. I have other web apps 
on this server using the same code (_layouts folder) and works without a 
problem. The impersonating user is a site collection admin. If I go to the 
image url I am asked to authenticate as expected, if I pass in the credentials 
I am using in the code then the image displayed.

I thought maybe it was an iis config issue but I have compared web.configs with 
another working site that implements this code also but it didn't seem to be 
missing anything.

Can anybody shed some light on this.

Regards,

Trent Allday

_______________________________________________
ozmoss mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

Reply via email to