2

How do I save an HTML page with all styles and images in C#? I need to make a programmatic implementation of a browser's 'Save' feature which doesn't rely on Internet Explorer (WebBrowser component).

Habip Oğuz
  • 921
  • 5
  • 17
Kristina
  • 15,859
  • 29
  • 111
  • 181

2 Answers2

1

I do not think this is very easy.

Download all the HTML for the page using webclient and write the text to an HTML-file. Then use an html-parser to find all linked images and save them in their sub-directory. Do the same for the CSS.

If you do not want to save all the images you can just add the URL of the page to the beginning of all links to images. Also, note that some URL:s are not relative and you will have to compensate for that. And don't forget to scan the css-file for all linked images

Oskar Kjellin
  • 21,280
  • 10
  • 54
  • 93
1

I have a similar thing to solve. Biggest problems for you will be the images that come from CSS, they are very difficult to parse.

So, I chose to use FiddlerCore to achieve that.

Might help you too.

The difficult part of your task is to create your own structure, and change image paths accordingly.

ra00l
  • 570
  • 4
  • 20