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

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.

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.

>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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.