How to embed and access xslt file as a project resource file?

Posted on 2008-11-05
Last Modified: 2008-11-05
1. As a part of my project I am using XSLT transformation to transform XML file to HTML format.
Can I avoid the loading of the xslt file from the hard disk and distribute the application with the xslt file as  embedded resource?

I suppose, I have to include the file to the project and on the properties dialog to select: Embedded Resource.

How to access then the file stream in the particular snipped code attached?

2. Is there any version of a kind of Xsl transformation class  that does render direct to a string instead to a file stream?
XslCompiledTransform xslt = new XslCompiledTransform();


string path = Path.GetDirectoryName(Application.ExecutablePath);



Open in new window

Question by:koleto115
    LVL 8

    Expert Comment

    In the System.Reflection namespace is the Assembly object.

    Assembly.GetManifestResourceStream(string name)

    Where name is the assembly's namespace + the project directory + the filename in dotted notation.

    e.g. Assembly.GetManifestResourceStream("MyProject.MyXMLAssembly.XSLTDir.MyXSLT.xslt")
    LVL 8

    Expert Comment

    Actually, you need to use the GetExecutingAssembly method too :

    LVL 8

    Accepted Solution

    Part #2 :

    There are overloads to write to a stream or XmlWriter on the Transform method.  None of them take a filename path as their input though so you'll have to read into XmlDocument first and use an XsltArgumentList object.  Something along these lines :

                XslTransform xslt = new System.Xml.Xsl.XslTransform();
                XsltArgumentList xal = new System.Xml.Xsl.XsltArgumentList();
                XmlDocument xml = new XmlDocument();
                MemoryStream transformedXmlBuffer = new MemoryStream();
                XmlTextWriter xtw = new XmlTextWriter(transformedXmlBuffer, Encoding.UTF8);
                xslt.Transform(xmlInput, xal, xtw);
                string transformedXml = Encoding.UTF8.GetString(transformedXmlBuffer.GetBuffer());

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    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…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now