Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public String ConvertImageURLToBase64(String url)
StringBuilder _sb = new StringBuilder();
Byte[] _byte = this.GetImage(url);
_sb.Append(Convert.ToBase64String(_byte, 0, _byte.Length));
return _sb.ToString();
private byte[] GetImage(string url)
Stream stream = null;
byte[] buf;
WebProxy myProxy = new WebProxy();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
stream = response.GetResponseStream();
using (BinaryReader br = new BinaryReader(stream))
int len = (int)(response.ContentLength);
buf = br.ReadBytes(len);
catch (Exception exp)
buf = null;
return (buf);
Copy link

talhakaanozkan commented Mar 20, 2020

{"'System.Net.FileWebRequest' türündeki nesne 'System.Net.HttpWebRequest' türüne atılamadı."}
not working.

Copy link

malkitsingh commented Mar 21, 2020

hi @talhakaanozkan
This code was written long back, make sure you are importing all the required dependencies.

Copy link

rahulbagal commented Sep 24, 2020

Thanks. Its a quick helpful reference. working fiddle -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment