Click here to Skip to main content
15,743,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi codeproject members

is there anyway calling the files in a dll and such as a third party exe.

i mainly want it so i can store all my files in a separate location and be able to call the file direct from the dll it self.
is this possible .

What I have tried:

i tried many sites but can see the option am looking for.
Updated 13-Feb-17 23:03pm

1 solution

Yes, it's possible:
string GetResourceFile(string assemblyPath, string nameSpace, string fileName)
    Assembly assembly = Assembly.LoadFrom(assemblyPath);
    string resourceName = nameSpace + "." + fileName;
    string resource = null;
    using (Stream stream = assembly.GetManifestResourceStream(resourceName))
        using (StreamReader reader = new StreamReader(stream))
            resource = reader.ReadToEnd();
    return resource;

For example, if MyAssembly has a folder "Resources", containing a folder "TextFiles", containg an embedded resource text file "RevisionHistory.txt":
GetResourceFile(@"D:\Testing\MyAssembly.dll", "MyAssembly.Resources.TextFiles", "RevisionHistory.txt");
Share this answer
W Balboos, GHB 14-Feb-17 7:18am    
Wow - where did you learn all that stuff?
OriginalGriff 14-Feb-17 8:01am    
I embed a "ToDo.txt" and "RevisionHistory.txt" file in each of my assemblies so I can refer to the history file in the "About" form, and update the ToDo from outside VS.
This allows me to include "sub histories" for component assemblies.
oxzy's Modz uk 14-Feb-17 10:24am    
is there any chance seeing a open source so i can see how it works ?
OriginalGriff 14-Feb-17 10:33am    
You've got the open source! It's all in text in the solution. All the other stuff is .NET framework code, which you can view via the Reference Sources.
oxzy's Modz uk 14-Feb-17 10:38am    
the problem i am having is where to place it , inside the main exe class or inside the dll.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900