locked
Embedding WebResource in .dll RRS feed

  • Question

  • User-1067372690 posted
    I'm trying to develop a simple web control library with Visual C# Express that I will then link to in VWD Express.

    One of the controls that I am developing is a simple "back to top" composite server control made up of an image and a link. I want the image to be embedded in the .dll as a WebResource.

    In Visual C# I have the following:

    1) In the root directory of my project an image called "top.gif". It's Build Action is "Embedded Resource" and it is set to Do Not Copy To Output Directory.

    2) In the AssemblyInfo.cs I hav added "[assembly: WebResource("top.gif", "img/gif")]"

    3) The control's code looks like:

    using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    namespace com.mynamespace.controls
    {
        [DefaultProperty("LinkText")]
        public class JumpToTop : CompositeControl
        {
            #region "Instance Variables"

            private string m_text = "Jump To Top";
            private int m_yOffset = 0;

            #endregion

            [Browsable(true)]
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("Jump To Top")]
            public string LinkText
            {
                get { return m_text; }
                set { m_text = value; }
            }

            [Browsable(true)]
            [Bindable(true)]
            [Category("Behavior")]
            [DefaultValue(0)]
            public int TopHeight
            {
                get { return m_yOffset; }
                set { m_yOffset = value; }
            }

            protected override void CreateChildControls()
            {
                if (!ChildControlsCreated)
                {
                    Image img = new Image();
                    img.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "top.gif");

                    HtmlAnchor a = new HtmlAnchor();
                    a.HRef = "javascript:scroll(0," + m_yOffset + ")";
                    a.InnerText = LinkText;

                    this.Controls.Add(img);
                    this.Controls.Add(a);
                    base.CreateChildControls();
                }
            }
        }
    }

    In VWD I have the control on a page, and everything renders correctly with a link to WebResource.axd, but the image can't be found.

    Anyone have any idea what I'm doing wrong?

    Thanks,
    Luke


    Friday, January 13, 2006 12:58 PM

All replies