2

Screenshots below are from the Solution Explorer Pane:


I have a class in Folder DataAccess that needs to access a resource in Folder data. I get the following error message.

System.IO.IOException: Cannot locate resource 'data/danio_rerio.xml'.

Does not Work If:

Does not Work

It works if:

It works

Folder data is a child folder within Folder DataAccess. Is it possible for me to use the following syntax:

foldername/somefile.someextension

to access resources within the project that are in seperate folders?


Edit: I do not want to hard code locations to my directories.

Community
  • 1
  • 1
Kiang Teng
  • 1,675
  • 4
  • 23
  • 42
  • What is the "Deployment" setting for these files. Generally resources are bundled into your assembly at compile-time, and then accessed through a `ResourceStream` rather than a `FileStream`. – Ben Voigt Jan 01 '11 at 16:54

2 Answers2

2

When you run your application, the running directory becomes your "active directory"

Suppose you have

c:\myproject\bin\debug\myapp.exe

When you run the application you try to search

c:\myproject\bin\debug\foldername\somefile.someextension

what you actually want could be close to

c:\myproject\data\daniorenio.xml

so you'll want to search the following directory

c:\myproject\bin\debug\..\..\data\daniorenio.xml

The .. operator tells that you want to go back in the directory hierarchy

However this is assuming your binary will be in a lower branch than your ressource. What I actually do is copy everything I absolutely need for runtime inside a special directory such as

c:\myproject\RuntimeRequired

This way I can issue a post build event like this (In Project/Properties/Build-Events/Post-Build)

copy /Y "$(ProjectDir)RuntimeRequired*" "$(OutDir)"

Eric
  • 19,525
  • 19
  • 84
  • 147
0

I found the answer myself. Should have searched more before offering a bounty -_-

Pack URIs in WPF [Source]

Community
  • 1
  • 1
Kiang Teng
  • 1,675
  • 4
  • 23
  • 42