Print/PrintPreview xml transformed file/html file from Windows form(c#)

Hi,
I have an XML document that uses a schema and styesheet and can be displayed as HTMl in a browser;
it contains tables, etc.
I am trying to display the file using the PrintPreview dialog; but a blank document is displayed.
Am I missing some step here?
Result.html is what I want to display in the printpreview dialog and then print.
The code is as follows:
private void PrintBtn_Click(object sender, EventArgs e)
        {
            ReadDocument();
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }

        private void ReadDocument()
        {          
            string tempPath = System.IO.Path.GetTempPath();
            string srcDocName =  tempPath + "Result.xml"; //original XML file
            string destDocName = tempPath + "Result.html";
            // Load the style sheet.
            XslCompiledTransform xslt = new XslCompiledTransform();
            xslt.Load(tempPath + "Result.xsl");
            // Execute the transform and output the results to a file.
            xslt.Transform(srcDocName, destDocName);// Result.XML is transformed to Result.html
                       printDocument1.DocumentName = destDocName;
            using (FileStream stream = new FileStream(srcDocName, FileMode.Open))
            using (StreamReader reader = new StreamReader(stream))
            {
                documentContents = reader.ReadToEnd();
            }
            stringToPrint = documentContents;
        }

        void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            int charactersOnPage = 0;
            int linesPerPage = 0;
            // Sets the value of charactersOnPage to the number of characters
            // of stringToPrint that will fit within the bounds of the page.
            e.Graphics.MeasureString(stringToPrint, this.Font,
                e.MarginBounds.Size, StringFormat.GenericTypographic,
                out charactersOnPage, out linesPerPage);
            // Draws the string within the bounds of the page.
            e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
            e.MarginBounds, StringFormat.GenericTypographic);
            // Remove the portion of the string that has been printed.
            stringToPrint = stringToPrint.Substring(charactersOnPage);
            // Check to see if more pages are to be printed.
            e.HasMorePages = (stringToPrint.Length > 0);
            // If there are no more pages, reset the string to be printed.
            if (!e.HasMorePages)
                stringToPrint = documentContents;
        }
Enid_JPAsked:
Who is Participating?
 
Enid_JPAuthor Commented:
Or is it possible to open the IE browser and then open the browser's print preview dialog?
0
All Courses

From novice to tech pro — start learning today.