Picturebox Throws Error 401 Unauthorized
Environment
Product | Progress® Telerik® Reporting |
Report item | PictureBox |
Description
The error might be thrown when the report contains a PictureBox whose Value is a URL. In general, when you provide an URL as a PictureBox.Value, we use a WebClient to download the image. At that point, the connection to server fails with the statement that the application's process is not authorized to get the resource.
Error Message
The remote server returned an error:(401) Unauthorized.
Solution
You have to create a User Function that will download the image after authorizing, and returns it (e.g. as type Bitmap) for the picture box value.
The User Function (without authorization) might look as follows:
public static Bitmap GetImage(string url)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(url);
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
Bitmap bitmap = new Bitmap(responseStream);
return bitmap;
}
Another option is to return the image as byte[]. Note that it will be necessary to authorize the request to successfully download the image from the URL.