How do i download all images from a List<string> with many links for images inside?
<pre><code>private List&lt;string&gt; retrieveImages(string address)
{

    System.Net.WebClient wc = new System.Net.WebClient();
    List&lt;string&gt; imgList = new List&lt;string&gt;();
    doc.Load(wc.OpenRead(address)); //or whatever HTML file you have 
    HtmlNodeCollection imgs = doc.DocumentNode.SelectNodes("//img[@src]");
    if (imgs == null) return new List&lt;string&gt;();

    foreach (HtmlNode img in imgs)
    {
        if (img.Attributes["src"] == null)
            continue;
        HtmlAttribute src = img.Attributes["src"];

        imgList.Add(src.Value);
        //Image imgDownload = GetImage(src.Value);
        //imgDownload.Save(@"d:\myImages");
    }
    return imgList;
}
</code></pre>

<p>In some case the List imgList contain 33 items and it looks like that:</p>

<p>In the first place <code>[0]</code> I see: <code>/images/experiments/nav_logo78.png</code>   as a link for the image I don't see and http in the start or www just start with <code>/images</code></p>

<p>Then in place <code>[1]</code> I see: <code>//maps.gstatic.com/mapfiles/transparent.png</code></p>

<p>Then after some items in place [10]  I see: <a href="http://mt1.google.com/vt/lyrs=m@186000000&amp;hl=iw&amp;src=app&amp;x=75&amp;y=51&amp;z=7&amp;s=Gali" rel="nofollow">http://mt1.google.com/vt/lyrs=m@186000000&amp;hl=iw&amp;src=app&amp;x=75&amp;y=51&amp;z=7&amp;s=Gali</a></p>

<p>Im not sure what gali is I don't see <code>.bmp .gif</code> or <code>.png</code> images just Gali.</p>

<p>What I want is to download all the this images from each link and save it to my hard disk.
So I have this function for the download:</p>

<pre><code>private Image GetImage(string url)
{
    System.Net.WebRequest request = System.Net.WebRequest.Create(url);

    System.Net.WebResponse response = request.GetResponse();
    System.IO.Stream responseStream = response.GetResponseStream();

    Bitmap bmp = new Bitmap(responseStream);

    responseStream.Dispose();

    return bmp;
} 
</code></pre>

<p>When im using this GetImage function in the retrieveImages() function it dosent do anything the program even dosent owrk I mean the List imgList is empty. If I mark this two lines as it is now:</p>

<pre><code>//Image imgDownload = GetImage(src.Value);
//imgDownload.Save(@"d:\myImages");
</code></pre>

<p>If I mark them with // not ot use them then evrything is working but if im using them nothing is working and its not saving anything to my hard disk.</p>

<p>What should I do?</p>

<p>Edit:</p>

<p>I just changed my retrieveImages function to this:</p>

<pre><code>private List&lt;string&gt; retrieveImages(string address)
        {

            System.Net.WebClient wc = new System.Net.WebClient();
            List&lt;string&gt; imgList = new List&lt;string&gt;();
            doc.Load(wc.OpenRead(address)); 
            HtmlNodeCollection imgs = doc.DocumentNode.SelectNodes("//img[@src]");
            if (imgs == null) return new List&lt;string&gt;();

            foreach (HtmlNode img in imgs)
            {
                if (img.Attributes["src"] == null)
                    continue;
                HtmlAttribute src = img.Attributes["src"];

                imgList.Add(src.Value);
                wc.DownloadFile(src.Value ,  @"d:\MyImages\my.gif");
            }
            return imgList;
        }
</code></pre>

<p>I used a breakpoint on the line wc.DownloadFile and it throw me an exception: Webexception Was Caught</p>

<p>Could not find a part of the path 'D:\textinputassistant\tia.png'.</p>

<p>In src.Value it waontin in this case: /textinputassistant/tia.png 
So you told me to avoid links that have not http or https or www in the start i will fix it.
The question is if the exception is since this line start with / and it dosent have any http/s/www ?</p>

<p>The full exception:</p>

<pre><code>System.Net.WebException was caught
  Message=Could not find a part of the path 'D:\textinputassistant\tia.png'.
  Source=System
  StackTrace:
       at System.Net.WebClient.DownloadFile(Uri address, String fileName)
       at System.Net.WebClient.DownloadFile(String address, String fileName)
       at GatherLinks.Form1.retrieveImages(String address) in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 328
       at GatherLinks.Form1.webCrawler(String url, Int32 levels, DoWorkEventArgs eve) in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 97
  InnerException: System.Net.WebException
       Message=Could not find a part of the path 'D:\textinputassistant\tia.png'.
       Source=System
       StackTrace:
            at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
            at System.Net.FileWebRequest.GetResponseCallback(Object state)
       InnerException: System.IO.DirectoryNotFoundException
            Message=Could not find a part of the path 'D:\textinputassistant\tia.png'.
            Source=mscorlib
            StackTrace:
                 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
                 at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
                 at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
                 at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
                 at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
</code></pre>

<h2>                InnerException:</h2>

<p>Just added a filter so it will save only links that start with http:</p>

<pre><code>private List&lt;string&gt; retrieveImages(string address)
        {

            System.Net.WebClient wc = new System.Net.WebClient();
            List&lt;string&gt; imgList = new List&lt;string&gt;();
            doc.Load(wc.OpenRead(address));
            HtmlNodeCollection imgs = doc.DocumentNode.SelectNodes("//img[@src]");
            if (imgs == null) return new List&lt;string&gt;();

            foreach (HtmlNode img in imgs)
            {
                if (img.Attributes["src"] == null)
                    continue;
                HtmlAttribute src = img.Attributes["src"];

                imgList.Add(src.Value);
                if (src.Value.Contains("http"))
                {
                    wc.DownloadFile(src.Value, @"d:\MyImages\my.gif");
                }
            }
            return imgList;
        }
</code></pre>

<p>Now src.Value contain: <a href="http://mt1.google.com/vt/lyrs=m@186000000&amp;hl=iw&amp;src=app&amp;x=75&amp;y=51&amp;z=7&amp;s=Gali" rel="nofollow">http://mt1.google.com/vt/lyrs=m@186000000&amp;hl=iw&amp;src=app&amp;x=75&amp;y=51&amp;z=7&amp;s=Gali</a></p>

<p>Then after it trying to download im getting exception: WebException Was Caught</p>

<p>The remote server returned an error: (403) Forbidden.</p>

<pre><code>System.Net.WebException was caught
  Message=The remote server returned an error: (403) Forbidden.
  Source=System
  StackTrace:
       at System.Net.WebClient.DownloadFile(Uri address, String fileName)
       at System.Net.WebClient.DownloadFile(String address, String fileName)
       at GatherLinks.Form1.retrieveImages(String address) in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 330
       at GatherLinks.Form1.webCrawler(String url, Int32 levels, DoWorkEventArgs eve) in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 97
  InnerException: 
</code></pre>

<p>The question is if the exception throw up since the site in this case google is blocking downloads or since the link end with Gali wich is im not sure what type of file it is ?</p>
