Question: I have a C# code behind file that gets dynamically generated HTML from a server and converts it to a PDF. In the HTML there are `<link rel="stylesheet">` elements that reference external stylesheets as well as many `<img>` tags. 

All of these files, images and stylesheets, come from `www.example.com`, and I'm trying to make all elements come from `static.example.com` with the same url instead. I've used the obvious `stringName.Replace("www.example.com","static.example.com")` to replace the elements in the HTML, but is there any way to do so for the references in the CSS file?

FOR EXAMPLE:   

`background-image:url('www.example.com/bg.png');`  

needs to become   

`background-image:url('static.example.com/bg.png');`  

in the external file.

Any ideas on approach? Creativity is welcome; I'm up for anything!

Thanks :)

Answer: 
Since you say "code behind file"... are you doing this in ASP.NET?

You could use String.Replace functions in the HTML code to change `<link href="www.example.com/cssfile.css">` to `<link href="fixcss.ashx?file=www.example.com/cssfile.css">`. Then write a fixcss.ashx to retrieve the CSS file and perform the string replacements on it.
You may use filestream to get the file and then replace by the code you have used.Other approaches are open

You may find this like helpful

[CSS Parser](http://www.codeproject.com/KB/recipes/CSSParser.aspx)

[Reading and Parsing a CSS file](http://www.c-sharpcorner.com/UploadFile/rahul4_saxena/3095/)