Search code examples
c#dlldirectoryresources

Find the path in dll


I have a dll file as a resource in my project. Now I would like to access the directory folder in the dll. E.g. Image dll (In Image.dll -> \Image\PresetFolder)

I would like to Directory.Getdirectories() folder path in the Image.dll

How could I can achieve this in c#???


Solution

  • At last, my friend provide me the answer, you have to load the dll first before get the directory path with code

    private string[] GetAllResourcePath()
    {
        Assembly assembly = Assembly.Load("ImageDLL");
        string resName = "ImageDLL.g.resources";
            using (var stream = assembly.GetManifestResourceStream(resName))
            {
                using(var reader = new ResourceReader(stream))
                {
                    return reader.Cast<DictionaryEntry>().Select(x => (string)x.Key).ToArray();
                }
            }
    }
    

    From this func, it will return all the resource directory path, and you can just filter out by using .Where() linq to get the directory you want.