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.GetExecutingAssem bly();
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.Proper ties.Resou rces.resou rces
It is not reading the resource names inside the dll file . Why ??
Is something worng with my code ?
thanks
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.GetExecutingAssem
string[] resNames = a.GetManifestResourceNames
int len = resNames.Length;
for (int i = 0; i < len;i++ )
{
MessageBox.Show("filenames
}
It is giving the following output :--
WindowsApplication3.Form1.
WindowsApplication3.Proper
It is not reading the resource names inside the dll file . Why ??
Is something worng with my code ?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yup. works gt8 !!
thanks.
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....
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....
The xsl files are embedded in the dll and you are looking at resources in the winforms executable.