سؤال

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