1,105,578 Community Members

Help to print the XML file

Member Avatar
FaridMasood
Junior Poster in Training
59 posts since Mar 2007
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

If someone has any idea that how to print the xml file.

Member Avatar
ChaseVoid
Junior Poster
116 posts since Aug 2007
Reputation Points: 30 [?]
Q&As Helped to Solve: 12 [?]
Skill Endorsements: 0 [?]
 
0
 

Didn't you post the same question in the C# forum?

Have you tried searching the web? Just go into the MSDN documentation, you'll find all your answers there.

To print XML form a dataset, you can use the WriteXml() function of the DataSet class.

Member Avatar
FaridMasood
Junior Poster in Training
59 posts since Mar 2007
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Didn't you post the same question in the C# forum?

Have you tried searching the web? Just go into the MSDN documentation, you'll find all your answers there.

To print XML form a dataset, you can use the WriteXml() function of the DataSet class.

Thank you,
I fact i have posted this after searching over two days over internet but still unable to find a way to print the XML file to printer. Please help me.

Member Avatar
ChaseVoid
Junior Poster
116 posts since Aug 2007
Reputation Points: 30 [?]
Q&As Helped to Solve: 12 [?]
Skill Endorsements: 0 [?]
 
0
 

>I fact i have posted this after searching over
>two days over internet
Well it seems like you haven't searched well. Anyways, you can find all the information about it in MSDN.
Just create a PrintDialog object and use it print the file.

System.IO.StreamReader fileToPrint;
System.Drawing.Font printFont;

//Write the following in the PrintButton 
//CLick Event

string printPath = this.textBox1.Text;
            fileToPrint = new System.IO.StreamReader(printPath);
            printFont = new System.Drawing.Font("Arial", 10);
            printDocument1.Print();
            fileToPrint.Close();

//In the PrintDialog's PrintPage Event 
//Handler do the following
float yPos = 0f;
            int count = 0;
            float leftMargin = e.MarginBounds.Left;
            float topMargin = e.MarginBounds.Top;
            string line = null;
            float linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
            while (count < linesPerPage)
            {
                line = fileToPrint.ReadLine();
                if (line == null)
                {
                    break;
                }
                yPos = topMargin + count * printFont.GetHeight(e.Graphics);
                e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos,
                    new StringFormat());
                count++;
            }
            if (line != null)
            {
                e.HasMorePages = true;
            }

//Now in the browse button, form where 
//you get the xml filename into the 
//textbox, do the following in it's Click 
//Event.

OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                textBox1.Text = openFileDialog1.FileName;
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article