0

I have a console application which references a dll DomainLayer. In DomainLayer, one of the classes uses a image in DomainLayer to display.

Currently I am using the exact path to that image.

How can I use a relative path to this image so that it gets picked up by both tests and Console Application

This is how the hierarchy looks:

-DomainLayer --Resources ---Images -----Logo.png

-ConsoleApplication

-UnitTests

Here's the code:

  workSheetIntroduction.Pictures.Add(5,1, @"C:\Users\Charu\Documents\Visual Studio 2013\Projects\AsmEpmReports\EmpReports.DomainLayer\Resources\Images\EpmLogo.png");
Charu
  • 2,679
  • 6
  • 35
  • 52
  • Could you give a code sample of what you are currently doing? – friedkiwi May 17 '15 at 08:36
  • You should use the image as a resource, not load it from disk. Set your image file's property to `Embedded Resource` and see [this](http://stackoverflow.com/questions/1192054/load-image-from-resources-area-of-project-in-c-sharp) post on how to load it. – nvoigt May 17 '15 at 08:41
  • @nvoigt I can't do that. The client has asked to use a relative path to an Image – Charu May 17 '15 at 08:42
  • 1
    @friedkiwi added code sample – Charu May 17 '15 at 08:42
  • Possible duplicate http://stackoverflow.com/questions/837488/how-can-i-get-the-applications-path-in-a-net-console-application – Max Brodin May 17 '15 at 08:49

1 Answers1

0

Could you try "EmpReports.DomainLayer\Resources\Images\EpmLogo.png" if the application is being run from "C:\Users\Charu\Documents\Visual Studio 2013\Projects\AsmEpmReports\"?

Also, make sure the resources are being copied to the output directory and that you reference the DLLs properly from within the solution.

friedkiwi
  • 2,158
  • 8
  • 29
  • 52