Skip to content

Image of the remote site

Chevy Mark Sunderland

Asked Dec 15, 2012, 10:29 AM EST1 answer
Share
LinkedInX
Image of the remote site

Hello guys!

I need your help.
This is code of my net page (C#).

I don't have error but in the output of webpage I don't see the image of the remote site, but I see an icon undefined...

How can i do it?
Can someone test my code?
please

Any help?
Thank you.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    thank you for help.
    as a matter a fact are authorized to use the image... [:)]

    this is the solution:

    [QUOTE]2. Grab the image directly instead of the surrounding HTML[/QUOTE]

    [CODE]using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net;
    using System.IO;
    using System.Drawing;

    public partial class CallRemote_Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    string url = "http://www.meteowebcam.it/export/toscana_1355612400_0.jpg";
    string file_name = Server.MapPath(".") + "\\toscana_1355612400_0.jpg";
    save_file_from_url(file_name, url);
    }

    public string getHtml(string url)
    {
    try
    {
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
    myRequest.Method = "GET";
    WebResponse myResponse = myRequest.GetResponse();
    StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
    string result = sr.ReadToEnd();
    sr.Close();
    myResponse.Close();
    return result;
    }
    catch (Exception exception)
    {
    return "The following error occurred: " + exception;
    }
    }

    public void save_file_from_url(string file_name, string url)
    {
    byte[] content;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    WebResponse response = request.GetResponse();
    Stream stream = response.GetResponseStream();
    using (BinaryReader br = new BinaryReader(stream))
    {
    content = br.ReadBytes(500000);
    br.Close();
    }
    response.Close();
    FileStream fs = new FileStream(file_name, FileMode.Create);
    BinaryWriter bw = new BinaryWriter(fs);
    try
    {
    bw.Write(content);
    }
    finally
    {
    fs.Close();
    bw.Close();
    }
    }

    }



    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="CallRemote_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">









    [/CODE]
    0