dectecting Background-Color setting

S

Sam

Hi all

I'm looking for a way to detect the background color of my internal webpage
through a stylesheet. And so far, the only solution I find is to open the
styles.css file and parse the BACKGROUND-COLOR field. The problem I'm
having is that I don't know the exact absolute path of the stylesheet file
(styles.css) to access it using stream reader. I have tried to use the
"Path.GetFullPath" method of the system.IO to get the absolute path but this
method does not seem to return the correct path. It does with the Window
app.

1. Is there a way to open this file based on relative path of the web
current directory
2. Does anyone have any other way to find BACKGROUND-COLOR setting?

Thank You

Sam
 
G

Guest

1. Is there a way to open this file based on relative path of the web
current directory

Yes, use the Server.MapPath command.

i.e. Server.MapPath("/MyFolder/Test.css") will return c:\inetpub\wwwroot
\MyFolder\test.css.
2. Does anyone have any other way to find BACKGROUND-COLOR setting?

Manual parsing is the only way : (
 
J

Juan T. Llibre

You could do this :

1. Make your body element a GenericHtml Control
by adding ID and runat attributes :

<body id="Body1" runat="server">

2. Access the background-color :

string var = Body1.Attributes["bgcolor"];
or
dim var as string = Body1.Attributes("bgcolor")

You could also use Steven Cheng's code-behind code :

<body id="bd" runat="server" >
===================

public class BgColorPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtColor;
protected System.Web.UI.WebControls.Button btnSubmit;
protected HtmlGenericControl bd;
===========================

private void btnSubmit_Click(object sender, System.EventArgs e)
{
System.Drawing.Color bgcolor =
System.Drawing.ColorTranslator.FromHtml(txtColor.Text);

bd.Style["BACKGROUND-COLOR"] = System.Drawing.ColorTranslator.ToHtml(bgcolor);
}

That code works for setting it.
For retrieving it, if you use that code, you could just use :

string var = bd.Style["BACKGROUND-COLOR"];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top