I am trying to programatically save the images from a website, I have tried both the
webClient.DownloadFile
method and HttpWebRequest.Create as below but keep hitting - $exception {"The remote server returned an error: (407) Proxy Authentication Required."} System.Exception {System.Net.WebException}
If I can right click and save the image whats the difference, is there any other way?
Code:private String LocalizeImages(String htmlText) { String parsedtext = htmlText; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(parsedtext); HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//img[@name]"); if (nc != null) { foreach (HtmlNode link in nc) { HtmlAttribute source = link.Attributes["src"]; String fullfilename = source.Value; String filename = Path.GetFileName(fullfilename); System.Net.WebClient webClient = new WebClient(); String target = Server.MapPath(@"\images\pdfImages\" + filename).ToString(); //webClient.DownloadFile(fullfilename, target); System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(fullfilename); System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse(); System.IO.Stream str = res.GetResponseStream(); if (str != null) { System.Drawing.Image img = System.Drawing.Image.FromStream(str); img.Save(target, System.Drawing.Imaging.ImageFormat.Jpeg); } res.Close();





Reply With Quote