How to programmatically load an HTML document to add a <head> to a document?

We supply HTML shell files with the client that we need to embed in the content and then display the HTML code.

Before displaying HTML with our content, I need to add several tags to the <head>client shell section , for example, links to our script files, css and some meta tags.

So what am I doing

string html = File.ReadAllText(wrapperLocation, Encoding.GetEncoding("iso-8859-1"));

and now I have full HTML. Then I searched for the predefined content in this line and inserted our content into it and displayed it.

How to create an instance of an HTML document and change the section <head>as needed?

edit: I do not want to reference System.Windows.Forms, so WebBrowser is not an option.

+1
5

, :

public virtual void PopulateCssTag(string tags)
{
    // tags is a pre-compsed string containing all the tags I need.
    this.Wrapper = this.Wrapper.Replace("</head>", tags + "</head>");
}
-1
+1

https://github.com/jamietre/CsQuery html dom.

var dom = CQ.Create(html);
var dom = CQ.CreateFromUrl("http://www.jquery.com");

dom.Select("div > span")
.Eq(1)
.Text("Change the text content of the 2nd span child of each div");

.

+1

WebBrowser / Document.

.

0

MasterPages? .

MasterPage < asp: ContentPlaceHolder > , , .

, View(), MasterPage web.config. , , MasterPage, , MasterPage/web.config.

0

Source: https://habr.com/ru/post/1754115/


All Articles