private void cmdPrint_Click(object sender, EventArgs e) { prgProgress.Value = 0; prgProgress.Maximum = treCharacters.Nodes.Count; // Write the Character information to a MemoryStream so we don't need to create any files. MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); // Being the document. objWriter.WriteStartDocument(); // <characters> objWriter.WriteStartElement("characters"); // Fire the PrintToStream method for all of the characters in the list. foreach (TreeNode objNode in treCharacters.Nodes) { Character objCharacter = new Character(); objCharacter.FileName = objNode.Tag.ToString(); objCharacter.Load(); objCharacter.PrintToStream(objStream, objWriter); prgProgress.Value++; Application.DoEvents(); } // Finish the document and flush the Writer and Stream. // </characters> objWriter.WriteEndElement(); objWriter.WriteEndDocument(); objWriter.Flush(); objStream.Flush(); // Read the stream. StreamReader objReader = new StreamReader(objStream); objStream.Position = 0; XmlDocument objCharacterXML = new XmlDocument(); // Put the stream into an XmlDocument and send it off to the Viewer. string strXML = objReader.ReadToEnd(); objCharacterXML.LoadXml(strXML); objWriter.Close(); // Set the ProgressBar back to 0. prgProgress.Value = 0; frmViewer frmViewCharacter = new frmViewer(); frmViewCharacter.CharacterXML = objCharacterXML; frmViewCharacter.SelectedSheet = "Game Master Summary"; frmViewCharacter.ShowDialog(); }