Im using regex to pull an image url from a site and would like my site to display the image from that url.
Anyone have an idea on how to do this since setting the image url to the response url isn't working?

Recommended Answers

All 3 Replies

If you want to display the image in the browser, I think, you should use an asp:control so you can reference it from the server side asp like this:

<body>
    <form runat="server">
        ...
        <asp:Image ID="Image1" runat="server" />
        ...
    </form>
</body>

To set the url use the following in the code behind:

Image1.ImageUrl = "//location/img.png";

Also I think there is a seperate forum for ASP/ASP.NET, you might find more able people to help you there.

I hope this helps!

First thanks for the reply and yeah someone was kind enough to move this message to the correct forum.
So far this is what i have tried:
(code behind)

<asp:Image ID="moviePicture" runat="server" Height="333px" Width="330px" />

(.cs code)

Regex imgLinkReg = new Regex(
                "name\\=\\\"poster\\\".*src\\=\\\"http\\:\\/\\/ia\\.media-imd" + "b\\.com\\/images\\/(.*?)\\\"",
                RegexOptions.CultureInvariant
                | RegexOptions.Compiled
                );
Match m1 = imgLinkReg.Match(responseFromServer);
if (m1.Success)
                {
                    moviePicture.ImageUrl = "http://ia.media-imdb.com/images/" + m1.Groups[1];
                }

--The Regex code was created using expresso and i have been able to put the right url to a label as a test. The imagebox (not a standalone box) starts out with a blank target url.
--I'm getting the impression that it needs to have the image reload after grabbing the correct url but I don't wish to reload the page to do it. Im thinking that i might want to use ajax but I'm hoping there is a simpler way to accomplish such a mundane task

As far as I understand, if you want to do this using C# you will have to reload at least part of the page. I do suspect there is a way of doing this using Javascript although I am no expert at web development.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.