We help IT Professionals succeed at work.

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

rye004
rye004 asked
on
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?
Comment
Watch Question

Software Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT
Commented:
How do I get the full url for imageElement?

Have you tried look for href property in your code?

imageElement.href

Open in new window

Author

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

Author

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