Page view counter

Problem with WebResourceAttribute and paths

Last post 04-23-2007 4:22 AM by andrewgarner. 2 replies.

Sort Posts:

  • Problem with WebResourceAttribute and paths

    04-20-2007, 12:09 PM
    • Loading...
    • andrewgarner
    • Joined on 11-25-2004, 1:38 AM
    • Shropshire, England
    • Posts 8
    • Points 27
    This problem has been puzzling me all day - I am attempting to embed resources within a class library, buy I can only get it to work when the files are within the root of the class library.

    My default namespace is Lighthouse.Software.Library.Core - I have added Test.css and Test.png to the root of the class library, then within the class I have the following code: 
    <Assembly: WebResource("Lighthouse.Software.Library.Core.Test.css", "text/css", PerformSubstitution:=True)> 
    <Assembly: WebResource("Lighthouse.Software.Library.Core.Test.png", "image/png")>

    Protected Overrides Sub CreateChildControls()

    Dim Stylesheet As New HtmlLink
    Stylesheet.Href = Me.Page.ClientScript.GetWebResourceUrl(GetType(MasterPage), "Lighthouse.Software.Library.Core.Test.css")
    Stylesheet.Attributes.Add("type", "text/css")
    Stylesheet.Attributes.Add("rel", "stylesheet")
    Stylesheet.Attributes.Add("media", "screen")
    Stylesheet.Attributes.Add("title", "Lighthouse")
    Me.Page.Header.Controls.Add(Stylesheet)

    End Sub
    This works correctly, however I wish to keep everything tidy by putting the resource files in sub-directories. I created a folder Resources containing folders Images and Styles and adjusted my code like so: 
    <Assembly: WebResource("Lighthouse.Software.Library.Core.Resources.Styles.Test.css", "text/css", PerformSubstitution:=True)> 
    <Assembly: WebResource("Lighthouse.Software.Library.Core.Resources.Images.Test.png", "image/png")>

    Protected Overrides Sub CreateChildControls()

    Dim Stylesheet As New HtmlLink
    Stylesheet.Href = Me.Page.ClientScript.GetWebResourceUrl(GetType(MasterPage), "Lighthouse.Software.Library.Core.Resources.Styles.Test.css")
    Stylesheet.Attributes.Add("type", "text/css")
    Stylesheet.Attributes.Add("rel", "stylesheet")
    Stylesheet.Attributes.Add("media", "screen")
    Stylesheet.Attributes.Add("title", "Lighthouse")
    Me.Page.Header.Controls.Add(Stylesheet)

    End Sub

    Now it no longer works - I have read that it is possible, but it won't work for me!

    Any suggestions would be much appreciated! 

    Filed under:
  • Re: Problem with WebResourceAttribute and paths

    04-22-2007, 7:09 AM
    Answer
    • Loading...
    • mosessaur
    • Joined on 07-11-2002, 6:40 PM
    • Cairo
    • Posts 353
    • Points 2,214

    It seems that C# compiler and VB.Net Compiler treat resources in deferent manner. And Actually I didn't know that before now.
    In case you still didn't resolve your issue, try this:

    Keep you first code as it is
    <Assembly: WebResource("Lighthouse.Software.Library.Core.Test.css", "text/css", PerformSubstitution:=True)>
    <Assembly: WebResource("Lighthouse.Software.Library.Core.Test.png", "image/png")>

    At the same time put your resources in folder as you wished. In VB.NET it seems that you just need to reference the default namespace without subsequent directories.

    Hope this would resolve your issue

    Muhammad M. Mosa Soliman
    Software Engineer
    Filed under:
  • Re: Problem with WebResourceAttribute and paths

    04-23-2007, 4:22 AM
    • Loading...
    • andrewgarner
    • Joined on 11-25-2004, 1:38 AM
    • Shropshire, England
    • Posts 8
    • Points 27
    Thank you so much! I've just tried that and it works!
Page 1 of 1 (3 items)