There wasn't a lot of documentation about embedding images to a dll so i've written my own demo to find out how it works. The demo checks if the entered number is above 1000 and below 100000 just to show different images. Ive attached the project below.
This is a class that handles the events. (i know, not very well written but heck, i'm sure you can refactor it yourself)
GeSHi (csharp):
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace EmbeddedImageDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/*
Image CalendarImage = new Image();
CalendarImage.ImageUrl = Page.ClientScript.GetWebResourceUrl(
this.GetType(),
//Replace following with the string entered in AssemblyInfo.cs
"EmbeddedImageDemo.Test.png");
*/
// img.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "EmbeddedImageDemo.Test.png");
// Image1.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "EmbeddedImageDemo.Test.png");
//works
//Image1.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(_Default), "EmbeddedImageDemo.Test.png");
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Int32 largeNumber = Convert.ToInt32(TextBox1.Text);
if (largeNumber < 1000)
{
Image1.
ImageUrl = Page.
ClientScript.
GetWebResourceUrl(typeof(_Default
),
"EmbeddedImageDemo.Resources.cancel.png");
Label1.Text = "Try again";
}
else if (largeNumber >= 1000 && largeNumber <= 100000)
{
Image1.
ImageUrl = Page.
ClientScript.
GetWebResourceUrl(typeof(_Default
),
"EmbeddedImageDemo.Resources.button_ok.png");
//Label1.Text = "value: " + TextBox1.Text;
Label1.Text = "Correct";
}
else
{
Image1.
ImageUrl = Page.
ClientScript.
GetWebResourceUrl(typeof(_Default
),
"EmbeddedImageDemo.Resources.help.png");
Label1.Text = "Value out of range";
}
}
catch (Exception)
{
Label1.Text = "Not a valid number";
}
}
}
}
Created by GeSHI 1.0.7.20
In short you need to do a few things to make it possible to embed images into a dll file.
1) add an image to your (web) project
2) select the image and go to property -> "Build Action" and choose "Embedded Resource"
3) add this in your AssemblyInfo.cs "[assembly: System.Web.UI.WebResource("namespace.directory.imageName.png", "img/png")]"
4) in your *.cs file add this to show the image: Image1.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(_Default), "namespace.directory.imageName.png");
5) press f5, if there are no errors test the project using your webbrowser (localhost:yourPortNumber)