Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to I make a DLL in C# containing xsl file ?

Posted on 2006-11-11
15
Medium Priority
?
787 Views
Last Modified: 2008-03-10
I have a set of xsl file which I have to convert into a DLL and use it in another project. this is urgent.

thanks in advance
0
Comment
Question by:paromitabanerjee
  • 7
  • 6
  • 2
15 Comments
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 750 total points
ID: 17922441
include it as an embedded resource ...

include it in your project then go to properties for it and select "Build Action" as embedded resource .. it will then be embedded into your DLL ..


Cheers,

Greg
0
 

Author Comment

by:paromitabanerjee
ID: 17922494
Hi,

thanks for the prompt reply. I am a fresher in C3. So bear with me.

I have made a project, in which I have embedded all the xsl files I have to use. (this project has a main method which does nothing) Then I compile this project. But I dont find any DLL being created ??

Could you tell me the step by step process for this.

let me explain what is required in the project. ----
This is a Desktop build. XSL files are used while generating PDFs. Uptill now the xsl files were a part of the Database. But now, they have to be made into a DLL, so that they go with the build. and then called from the main project.

Thanks in advance
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 750 total points
ID: 17922584
if you project has a main method it wouldnt be a dll .. it would be a .exe .. try starting with a "class library" project and add it to that if you want a .dll

http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=75 also shows tyou how to access it in case you are not aware.

Cheers,

Greg
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:bromose
ID: 17922651
Hi. You need to add the xslt to your project (it will then be compiled into your DLL). In your code You can get access to the XSLT using code like (in my case the filename is BygteqStyleDefXsl.xsl):


namespace ArtesaIP
{

    ///<summary>ItemPriceXSLT er implementeringen af ArtesaIP, der foretager tansformation af leverandør XML til Aretesa XML</summary>
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces(typeof(IArtesaItemPrice))]
    [ComVisible(true)]
    public class ItemPriceXSLT : IArtesaItemPrice
    {
        private int debugLevel;
        private XsltArgumentList XsltArg;
        private BygteqXslFunctions bygteqXslFunctions;
        private XmlDocument bygteqXsl;

 In a methoed:

                //Load BygteqStyleDefXsl.xsl
                Stream s = System.Reflection.Assembly.GetAssembly(System.Type.GetType("ArtesaIP.IArtesaItemPrice")).GetManifestResourceStream("ArtesaIP.BygteqStyleDefXsl.xsl");
                bygteqXsl.Load(new XmlTextReader(s));
                s.Close();

Hope this helps.
Best regards,
Kaj Bromose
0
 

Author Comment

by:paromitabanerjee
ID: 17922746
Hi All,

thanks for your prompt replies.

Here is what I have done so far,

1) Created a class Library project (Stylesheet50) and embedded all the xslt files in it (about 12 of them) using Build Action == embedded resource property. On compilation, it made a stylesheet50.dll file.
2) I my WinApp project (which has the main method) -- I have included the stylesheet50.dll as a reference.

Now I want to start accessing my xsl file. will using the Assembly methods given above allow me to access the xsl files in the dll ??

thanks in advance

0
 
LVL 3

Expert Comment

by:bromose
ID: 17922797
I am not quite sure. In my case the DLL is exposed as an COM DLL wich is called from a Microsoft Dýnamics (Navision) application.

That is why the
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces(typeof(IArtesaItemPrice))]
    [ComVisible(true)]
part of the code.

However I think it will work, since the Navision application in my case act as the exe app. in Your case, but it needs to ve tryed out.

Hope You will succed with the testing.

0
 
LVL 3

Expert Comment

by:bromose
ID: 17922821
Sorry - I forgot to give you a hint - you can link from the XSL style sheet to your own C# code by using the XsltArgumentList. I that way you may call your own C# methoeds as XSL functions from your XSL stylesheet - and you may even have a object holding data between multible stylings (fs. bulding an array in one styling to be used in an later styling).

0
 

Author Comment

by:paromitabanerjee
ID: 17922967
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

0
 
LVL 3

Accepted Solution

by:
bromose earned 750 total points
ID: 17923087
You should do somthing like this:

            System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(Type.GetType("PersonSystem.Program")); //Your EXE prog namespace and class
            System.Reflection.AssemblyName[] an = ass.GetReferencedAssemblies(); //Gives you the list of ref. DLL assemblies
            ass = System.Reflection.Assembly.Load(an[1]); //Find the right element and load it the you got the assemblie ref

           Stream s = ass.GetManifestResourceStream("ArtesaIP.BygteqStyleDefXsl.xsl");

Best regards,
Kaj Bromose


0
 

Author Comment

by:paromitabanerjee
ID: 17923123
mind the language while writing ur code !!!!
0
 
LVL 3

Expert Comment

by:bromose
ID: 17923178
Sorry - English is not my native language. I now se that my choise of variable name is unapropiet. I'm sorry if my language has offended anybody - it was clearly not the intention !!!
0
 

Author Comment

by:paromitabanerjee
ID: 17923193
Thats okie... :) I realized that later.

hey,

I tried the above code. Its reading all the System generated assemblies correctly but not the one that I created. :(  -- heres the code

System.Reflection.Assembly assm = System.Reflection.Assembly.GetAssembly(Type.GetType("WindowsApplication3.ProgramCheck"));
//Your EXE prog namespace and class
                System.Reflection.AssemblyName[] an = assm.GetReferencedAssemblies(); //Gives you the list of ref. DLL assemblies
                int len = an.Length;

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

any help ??

0
 

Author Comment

by:paromitabanerjee
ID: 17923215
Do I have to change or add anything im my assemblyInfo.cs file?

Following is the code in the assemblyInfo.cs  which is under the Properties folder :-

sing System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("StylesheetLTC50")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Company")]
[assembly: AssemblyProduct("StylesheetLTC50")]
[assembly: AssemblyCopyright("Copyright © Company 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("27dd18ef-534c-459f-bc54-60353a19222d")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

thanks.
0
 
LVL 3

Expert Comment

by:bromose
ID: 17923241
You need to make sure that Your DLL's are in the project. In VS 2005 Open the Solution Explorer vindow and click the "References". If your DLL name is not listed here, you need to right click references and choose add reference. Then select the "browse", and set focus on your DLL.

Once the DLL is in the References list it should work.

0
 

Author Comment

by:paromitabanerjee
ID: 17923266
yup it is a part of the reference.

Hey, if I use this it is giving me the embedded files :-

                Assembly a = Assembly.LoadFile("C:\\Visual Studio 2005\\Projects\\WindowsApplication3\\WindowsApplication3\\bin\\Debug\\StylesheetLTC50.dll");
                string[] resNames = a.GetManifestResourceNames();
                int len = resNames.Length;
                for (int i = 0; i < len; i++)
                {

                    Console.WriteLine(resNames[i]);
                    MessageBox.Show("filenames == " + resNames[i]);
                }

I will try to put a relative path now and see .

a BIG thanks for the prompt help provided by everyone.... :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question