In JavaScript I can easily get a value from a css file. For example, the width of a certain class. This is done in the question below:
How do you read CSS rule values with JavaScript?
I want to know the CSS width value in my C# code to calculate the width of my scroll area. What I have so far is:
int toDoWidth = 100;
using (StreamReader cssFile = File.OpenText(Server.MapPath("~/Content/Tracker.css")))
{
string line = null;
while ((line = cssFile.ReadLine()) != null)
{
if (line == ".my_note {")
{
line = cssFile.ReadLine();
if (line != null)
{
line = line.Substring(line.IndexOf(":")+2);
line = line.Substring(0, line.IndexOf("px"));
toDoWidth = line.AsInt();
}
break;
}
}
}
...
My code simply does not feel right. If later in development someone changes the CSS by adding a value before width in my_note class, then my code would not work anymore...
Is there a simpler/better way to open the CSS file and read a certain property in C# code?
p.s.: I'm reading/searching since years on Stack Overflow, but I thought it's time to post my first question ;)