Michael A
Michael A

Reputation: 9900

How do I load a CSS file with HTMLTextWriter

Using HTMLWriter I've been able to load individual pieces of CSS with the following:

protected static void FixHeaderStylesHeight(HtmlTextWriter writer)
{
    writer.RenderBeginTag(HtmlTextWriterTag.Style);
    writer.Write(".ms-siteicon-img { max-height: 80px; }");
    writer.RenderEndTag();
}

This is now getting more complicated and I'd like to load an external CSS file into the page, basically, if this was HTML I would use the following line:

<link rel="stylesheet" type="text/css" href="/stdtheme.css" />

How can I duplicate this kind of functionality using HtmlTextWriter?

Upvotes: 3

Views: 3046

Answers (1)

Justin Van Bibber
Justin Van Bibber

Reputation: 393

I don't have an IDE in front of me, but I believe I've done something like this in the past:

writer.AddAttribute(HtmlTextWriterAttribute.Href, "/stdtheme.css");
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
writer.RenderBeginTag(HtmlTextWriterTag.Link);

Upvotes: 3

Related Questions