Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write text in thsi format
Billing

Bill No:32 Time :30-12-1899 11:47:00 AM
Table No: 1 Date :08-04-2013 12:00:00 AM
-----------------------------------------------------------------------------------------------------
Category Name Item Name Quantity Price Total
--------------------------------------------------------------------------------------------------
Veg Paneer Tikka 2 200 400
Non Veg Butter Chicken 2 200 400
Veg Paneer masala 2 120 240

My code is: if(dt.Rows.Count>0)
{
StreamWriter sw = new StreamWriter("C:\\Test.txt");
sw.WriteLine( "\t\tBilling");
sw.WriteLine();
sw.Write("Bill No:");
sw.Write(dt.Rows[0][0].ToString());
sw.Write("\t");
sw.WriteLine("Time :"+dt.Rows[0][2].ToString());
sw.Write("Table No: "+dt.Rows[0][1].ToString());
sw.Write("\t");
sw.WriteLine("Date :"+dt.Rows[0][3].ToString());
sw.WriteLine("-----------------------------------------------------------------------------------------------------");
string category = "Category Name ";
sw.Write(category.ToString());
// int Catlenght = category.Length();
string ItemName = "Item Name ";
string qty = "Quantity ";
string price = "Price ";
string total = "Total";
sw.WriteLine("{0,0}{1,"+category.Length+"}{2,"+ItemName.Length+"}{3,"+qty.Length+"}{4,"+price.Length+"}", category, ItemName,qty,price, total);
C#
for (int i = 0; i < dt.Rows.Count; i++)
            {
                sw.Write("{0,0}{1," + category.Length + "}{2," + ItemName.Length + "}{3," + qty.Length + "}", dt.Rows[i][4].ToString(), dt.Rows[i][5].ToString(), dt.Rows[i][7].ToString(), dt.Rows[i][6].ToString());

}
sw.close();
Posted
Updated 7-Apr-13 22:28pm
v2
Comments
muneebalikiyani 8-Apr-13 5:05am    
Be more specific about the problem , and try using "sw.flush()" before you close the stream writter.

use System.Diagnostics.Process.Start..to know more visit this msdn link
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(v=vs.71).aspx[^]
try
System.Diagnostics.Process.Start("notepad.exe", @"C:\Test.txt");
 
Share this answer
 
v2
Hi Nabin,

What is the error you are getting ?

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900