static void Main(string[] args) { int ImageNo = VehicleDBManager.InsertImageFromFile(@"C:\Users\geoff\Pictures\Da Boys.jpg", "image/jpeg"); Console.WriteLine($"Inserted Image #{ImageNo}"); Console.ReadLine(); }
private static List <int> GetandStoreVehicleImages(string URL) { List <int> ImageNumbers = new List <int>(); List <string> FileList = new List <string>(); RetrieveVehicleDetail(URL); HtmlDocument DetailPage = VehicleDetail; HtmlNodeCollection DetailDiv = DetailPage.DocumentNode.SelectNodes($"//div[@id='photos']/ul/li"); Console.Write("Downloading pics "); foreach (HtmlNode a in DetailDiv) { if (!a.InnerHtml.Contains("ref")) { continue; } HtmlNode HRef = a.SelectSingleNode("a"); string PicUrl = "http:" + HRef.GetAttributeValue("href", "none"); if (PicUrl != "none") { Uri picURI = new Uri(PicUrl); string picFileName = picURI.Segments[picURI.Segments.Count() - 1].ToString(); FileList.Add(picFileName); using (var client = new WebClient()) { client.DownloadFile(PicUrl, $@"c:\temp\{picFileName}"); int ImageNo = VehicleDBManager.InsertImageFromFile($@"c:\temp\{picFileName}", "image/jpg"); ImageNumbers.Add(ImageNo); Console.Write("."); } } } foreach (string filename in FileList) { (new FileInfo(filename)).Delete(); } return(ImageNumbers); }