Show data of MemoryStream in a literal control

Posted on 2005-05-03
Last Modified: 2010-08-05
I am using the XMLtextwriter to create  XML data. The writer writes the data into a memorystream. Once it is finished I would like to show the XML data in a literal control, before I use an XSL file for a transformation.

My code:

        Dim oMemoryStream As New System.IO.MemoryStream
        Dim oXMLWriter As System.Xml.XmlTextWriter
        oXMLWriter = New System.Xml.XmlTextWriter(oMemoryStream, System.Text.Encoding.UTF8)

        With oXMLWriter
            .Formatting = System.Xml.Formatting.Indented
            .Indentation = 4
            .IndentChar = CChar(" ")

            Call WriteNavigationItems(oXMLWriter, PageInfo.AtaChapterID)

        End With


        oMemoryStream.Position = 0
        Dim XMLdoc As New XPathDocument(oMemoryStream)

        Dim stylesheet As New XslTransform
        stylesheet.Load("E:\BA - Projects\Bright Alley\wwwroot\FE\ba_controls\default\navigation.xslt")

        Dim oStringWriter As New System.IO.StringWriter
        stylesheet.Transform(XMLdoc.CreateNavigator(), Nothing, oStringWriter, Nothing)
        ltlNavigation.Text = oStringWriter.ToString

Question by:Kai77
    LVL 23

    Accepted Solution

    Dim memoryStream As New System.IO.MemoryStream
    Dim writer As New System.Xml.XmlTextWriter(memoryStream, System.Text.Encoding.UTF8)

    With writer
          .Formatting = System.Xml.Formatting.Indented
          .Indentation = 4
          .IndentChar = CChar(" ")
          Call WriteNavigationItems(writer, PageInfo.AtaChapterID)
    End With


    memoryStream.Position = 0
    Dim reader As New StreamReader(memoryStream)
    'getting the xml from the memory stream
    Dim value As String = reader.ReadToEnd()
    'now add that to your control

    memoryStream.Position = 0
    Dim document As New XPathDocument(memoryStream)


    Dim stylesheet As New XslTransform
    stylesheet.Load("E:\BA - Projects\Bright Alley\wwwroot\FE\ba_controls\default\navigation.xslt")

    Dim outputWriter As New System.IO.StringWriter
    stylesheet.Transform(document.CreateNavigator(), Nothing, outputWriter, Nothing)
    ltlNavigation.Text = outputWriter.ToString

    LVL 23

    Expert Comment

    it is important to use the proper naming conventions. Avoid the Hungarian notation as whatever that applied in VB is not necessarily correct in VB.NET

    All instances of classes are objects. Thus, there is no need to use the prefix o.


    Author Comment

    Ok thanks man

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    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…

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now