Web Browser - Saving Images

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • carj2ee
    New Member
    • Jun 2007
    • 6

    Web Browser - Saving Images

    I trying to write a program that will go to a website and get all the images and then save then on to a local drive.

    I am using a mshtml.HTMLImg variable and then directcasting the web page to mshtml document, and then retriving all images. I am able to retrieve all the names of the images. How do I store these images on to the local drive? Any help is appreciated.

    Thanks.
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    This demonstrates the concept of saving a file from a remote server to the local disk:
    Code:
    using System.Net;
    using System.IO;
     
    static public void DownloadImage(string url, string outputFile)
    {
    	byte[] byteBuffer;
    	HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(url);
    	WebResponse Rsp = Req.GetResponse();
    	Stream oStrm = Rsp.GetResponseStream();
    	using (BinaryReader oBR = new BinaryReader(oStrm))
    	{
    		byteBuffer = oBR.ReadBytes(500000);
    		oBR.Close();
    	}
    	Rsp.Close();
    	File.WriteAllBytes(outputFile, url);
    }
    Just dump it into your code and call it by DownloadImage(R emoteFile, LocalFile);

    Comment

    • carj2ee
      New Member
      • Jun 2007
      • 6

      #3
      Cool. This works. Thanks

      Comment

      Working...