Question

i am generating barcode from the website barcodes4.me. it generates an image on the url:http://www.barcodes4.me/barcode/qr/myfilename.png?value=My%20QR%20Code. now i want to save (upload) this file on a click event of a button. any idea how to do that

Was it helpful?

Solution

Try this:

private static System.Drawing.Image GetImg(string url)
{
    System.Drawing.Image tmpimg = null;
    var httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
    var httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
    Stream stream = httpWebReponse.GetResponseStream();
    tmpimg = System.Drawing.Image.FromStream(stream);
    return tmpimg;
}

And put this line in your click event handler:

GetImg("http://www.barcodes4.me/barcode/qr/myfilename.png?value=My%20QR%20Code").Save(Server.MapPath("~/Images") + "/barcode.png");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top