Link to home
Start Free TrialLog in
Avatar of paromitabanerjee
paromitabanerjee

asked on

C# How to get the resource names embedded in a DLL file?

I have .xsl file embedded in a dLL. I have added the dll as a reference in my current project.
And I want to get all the names of all files in the dll from my current project.

This is what I calling from the Main method.

When I just try to get the resource file names from the assemblies, it is not giving the proper file names. My code :

Assembly a = Assembly.GetExecutingAssembly();

 string[] resNames = a.GetManifestResourceNames();

int len = resNames.Length;

                for (int i = 0; i < len;i++ )
                {
                    MessageBox.Show("filenames == "+resNames[i]);
                }


It is giving the following output :--

WindowsApplication3.Form1.resources
WindowsApplication3.Properties.Resources.resources

It is not reading the resource names inside the dll file . Why ??

Is something worng with my code ?

thanks
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

You have got the wrong assembly.
The xsl files are embedded in the dll and you are looking at resources in the winforms executable.
ASKER CERTIFIED SOLUTION
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of paromitabanerjee
paromitabanerjee

ASKER

yup. works gt8 !!

thanks.
In your dll that contains the XSL files you could define a nice simple class called XSLLibrary that has a single static method like :

public static stream GetXSL(string nameOfFile){

    // in here you can handle all the extracting of the xsl from the dll etc

}

It doesn't necessarily have to return a stream, it could return an XMLDocument, or and XslTransform, whatever is most useful.
In anycase, it would encapsulate the logic of retrieving the XSL files into a single method :

XSLLibrary.GetXSL();

If at any point in future you wanted to change how this XSL was stored or distributed (for instance you wanted to have the xsl library published on a website and the application would retrieve xsl files from there) you could just change this one method and it would be done without having to change any ofl your other code.

Just a thought....