Solved

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

Posted on 2006-11-11
15
745 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 250 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 250 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now