Include rel link to stylesheet only if it exists.

Discussion in 'ASP.NET / ASP.NET Core' started by cilynx, Jan 24, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have my site setup with a many-layered tree structure. I use CSS heavily. I have a master stylesheet in my root. Some branches have their own stylesheet. Some twigs have their own stylesheet. Same pages have their own stylesheet.

    Every page has the same generated header. I want this header to walk the tree from the called page down to root and include all of the stylesheets that it comes to along the way.

    I was trying with a rather inefficient go at File.Exists(). File.Exists() works, but I can't get my starting directory. Both Environment.CurrentDirectory and System.AppDomain.CurrentDomain.BaseDirectory are set to my document root as opposed to the directory of the calling page.

    As of this moment, every page links to all of the lower branch's stylesheets whether they exist or not. While this works for presentation, it completely invalidates the entire site as well as just being bad form in general.

    Any suggestions?
     
  2. Well,just wondering,why would you want to check whether a particular CSS exisits ?Does you application generates or modifies CSS files dynamically in the Hierarchy that makes you check whether it exists or not?

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. You can use Server.MapPath(".") to get your current directory and Server.MapPath("/") to get your root directory.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  4. Thank you for the calls to grab my working and root directories. I can work what I need from there.

    As per why I need to detect the existence, not all of the CSS files exists. I don't want to include the rel links for the files that aren't there because it breaks the validation of the page and that's a big deal with our site. I'm not mangling the CSS in any way, just checking to see if it's there before calling it up.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page