Your image -> Properties -> Build Action -> Embedded Resource. It will be compiled with your control or library.
Hi, add the two images to a subforlder called images of your treeview control project. Then change their build action in the property grid from content to embeded resource.
In addition to that, you have to register those two images as embeded resources for your assembly in the assemblyinfo.cs file like this:
[assembly: System.Web.UI.WebResource("YourProjectsNameSpace.Images.plus.gif", "img/gif")]
[assembly: System.Web.UI.WebResource("YourProjectsNameSpace.Images.minus.gif", "img/gif")]
As those images will be embeded into your controls assembly now, you can access them using the ClientScriptManager like this:
string plusImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "YourProjectsNameSpace.Images.plus.gif");
string minusImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "YourProjectsNameSpace.Images.minus.gif");
OK, I found the answer in this article. I give credit to Andre Kraemer as the accepted answer, because he pointed me in the right direction. He could not know that there is a slight difference in the name structure between C# and VB!
Here is the solution that works for VB :
The important difference is that in VB, the file path is not included in the name.
In my example, the root namespace in the project is MyCompany.MyWebControls
and the image files is in a subfolder named Resources
. In C#, the subfolder is part of the resource name structure, but not in VB.
In C#, this would be:
[assembly: System.Web.UI.WebResource("MyCompany.MyWebControls.Resources.plus.gif", "image/gif")]
In VB, we must ignore the file path in the resource name path:
<Assembly: System.Web.UI.WebResource("MyCompany.MyWebControls.plus.gif", "image/gif")>
So when we know this, my full example will be:
In AssemblyInfo.vb:
<Assembly: System.Web.UI.WebResource("MyCompany.MyWebControls.plus.gif", "image/gif")>
<Assembly: System.Web.UI.WebResource("MyCompany.MyWebControls.minus.gif", "image/gif")>
In my RenderContents
override:
Dim lPlusImage As New WebControls.Image()
Dim lMinusImage As New WebControls.Image()
lPlusImage.ImageUrl = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "MyCompany.MyWebControls.plus.gif")
lMinusImage.ImageUrl = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "MyCompany.MyWebControls.minus.gif")
lPlusImage.RenderControl(output)
lMinusImage.RenderControl(output)
And voilá, it works!