I created a resource, but the files inside it appear as not existing

I have put my files as a resource in my C # program. Now I am trying to see if files exist or not via

      if(File.Exists(path)) 

      

but it doesn't go into the if block when even the path is a valid path to files inside resources. The files are DTDs that will be embedded as resources within an assembly at compile time and resolved as resources at run time. Please help. what could be the reason? and what am I missing?

0


a source to share


3 answers


If you want to access your resources in C # you must use the Properties.Resources class.

For instance:



string data = Properties.Resources.dtd

      

+2


a source


Since you have embedded the resource, the file (or resource) is embedded in the assembly manifest. You may have to grab the file as a resource stream from the manifest.



string filePath = Assembly.GetExecutingAssembly().GetName().Name+"." + resourceFileName; 
Stream fileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filePath);

      

+1


a source


File.Exists()

is for the filesystem only. You must be able to access your file with

myProject.Properties.Resources.Image01;

      

And there is no real reason to check if the file exists.

0


a source







All Articles