the following piece of code worked fine all day yesterday
public Image getImage()
{
String connectionString = "URL GOES HERE, CANT POST WORK DATA";
Image img;
HttpWebRequest request = WebRequest.Create(connectionString) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
img= Image.FromStream(reader.BaseStream);
}
return img;
}
It gets an image from a webservice provided by work, i used it a lot yesterday for the day but now all i get is the exception stated in the header on the line
img= Image.FromStream(reader.BaseStream);
the problem is its working for everyone else apart from me (you can manually type the url in to your browser and it displays the image in there, this is not working for me either)
Does anyone have any ideas?
Thanks
Two things:
1) The StreamReader is of not use, it’s only used for Text streams, you can use response.GetResponseStream() directly
2) The doc for Image.FromStream available here says “You must keep the stream open for the lifetime of the Image.”, so you must not create the stream with the ‘using’ statement, as it will be closed at block end.