Link to home
Start Free TrialLog in
Avatar of rye004
rye004Flag for United States of America

asked on

In C# how do I get the full URL from HTMLImgClass?

I am writing a program to download images from a web page.  I am able to download the images, but I would also like to log the full path of where it came from.

Below is the code that I have written.

            WebBrowser scrapeWebBrowser = new WebBrowser();

            scrapeWebBrowser.Navigate("http://yahoo.com");

            HTMLDocument objHtmlDocument = (HTMLDocument)scrapeWebBrowser.Document;

            foreach (HTMLImgClass imageElement in objHtmlDocument.images)
            {
                //HTMLImage
                WebClient client = new WebClient();
                string fileName = System.IO.Path.GetFileName(imageElement.href);
                client.DownloadFileAsync(new Uri(imageElement.href), System.IO.Path.Combine(@"L:\temp\imagedownload\", fileName));

                //How do I get the full url for imageElement?
            }

Open in new window


Is it possible to return the full URL from my declared variable imageElement?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rye004

ASKER

Hi!  Yes, I did look at imageElement.href.  It only returned the name for the current image.  Thanks!
Avatar of rye004

ASKER

I just tested again, and you are correct! Thank you again for your help! 😊