Skip to main content

3 posts tagged with "c#"

View All Tags

· 18 min read
Oleg Kulyk

How to download images with C#?

Downloading images programmatically in C# is a fundamental task in various applications, ranging from web scraping to automated testing. This comprehensive guide delves into different methods to achieve this, including the use of HttpClient, WebClient, and ImageSharp. Each method is explored with detailed code examples and best practices to ensure efficient and reliable image downloading.

The HttpClient class is a modern, feature-rich way to handle HTTP requests and responses, making it a popular choice for downloading images. Its flexibility and performance advantages are well-documented (Microsoft Docs). On the other hand, WebClient, although considered legacy, still finds use in older codebases due to its simplicity (Stack Overflow). For advanced image processing, the ImageSharp library offers robust capabilities beyond simple downloading, making it ideal for applications requiring image manipulation (Code Maze).

This guide also covers critical aspects such as asynchronous downloads, error handling, and memory management, ensuring that developers can create robust systems for downloading images in C#. By following these best practices, you can optimize performance and reliability, addressing common challenges encountered in real-world applications.

This article is a part of the series on image downloading with different programming languages. Check out the other articles in the series:

· 8 min read
Oleg Kulyk

How to parse HTML in .NET

HTML parsing is a vital part of web scraping, as it allows convert web page content to meaningful and structured data. Still, as HTML is a tree-structured format, it requires a proper tool for parsing, as it can't be property traversed using Regex.

This article will reveal the most popular .NET libraries for HTML parsing with their strong and weak parts.

· 5 min read
Oleg Kulyk

HTML Parsing Libraries - C#

Web sites are written using HTML, which means that each web page is a structured document. Sometimes the goal is to obtain some data from them and preserve the structure while we’re at it. Websites don’t always provide their data in comfortable formats such as CSV or JSON, so only the way to deal with it is to parse the HTML page.