문제

I have a Library project which i use it as a portable area project using MvcContrib.

Inside the Library project i am accessing a local image from code behind.

string imagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("Controls\\images\\expander_opened_hover.png"));
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(imagePath))
{
   // do somthing with this image
}

The code runs on the Library project, but when i am accessing the same function from a "host" project, i get an error that the file was not found. The file is set as Embedded Resource in the Library project, but it doesn't exists in the host project.

How can i set the path so it will find the embedded icon instead?

도움이 되었습니까?

해결책

May be like this:

var assembly = Assembly.GetExecutingAssembly();
var imageStream = _assembly.GetManifestResourceStream(
        "[AssemblyNamespace].Controls.images.expander_opened_hover.png");
var bitmap = new Bitmap(imageStream)

have a look here: http://support.microsoft.com/kb/319292

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top