Thursday, 15 August 2013

URL is not a recognised format, can I convert

URL is not a recognised format, can I convert

I want to display an image stored as a string in database table. When I
run the code I get the error "Invalid URI, format could not be
determined". Within the table the actual string is something like
this:13d2dr09-377-423c-993e-22db3l390b66
How do I convert this so it can be recognised.
string sAdImageUrl = myReader.GetString(3);
var image = new BitmapImage();
int BytesToRead = 100;
WebRequest request = WebRequest.Create(new
Uri(sAdImageUrl,UriKind.Absolute));
request.Timeout = -1;
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
BinaryReader reader = new BinaryReader(responseStream);
MemoryStream memoryStream = new MemoryStream();
byte[] bytebuffer = new byte[BytesToRead];
int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
while (bytesRead > 0)
{
memoryStream.Write(bytebuffer, 0, bytesRead);
bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
}
image.BeginInit();
memoryStream.Seek(0, SeekOrigin.Begin);
image.StreamSource = memoryStream;
image.EndInit();
imaPartners.Source = image;
}
}

No comments:

Post a Comment