Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone help me how to write data into a text document without using streamwriter in C# windows form.

Thanks.
Posted

You can use these methods for writing the text in text file without using streamwriter.

C#
File.WriteAllText(@"d:\test.txt","Hi how are you? \r\n Hello Word");
File.WriteAllLines(@"d:\test.txt","Hello Word");
 
Share this answer
 
Comments
Karthik Achari 5-Mar-14 1:44am    
can you help me,i want to write data from gridview.

Thanks.
Anand Gunasekaran 5-Mar-14 1:54am    
Sure.
Karthik Achari 5-Mar-14 2:02am    
Iam sending sample data please go through it and help me.


Gridview:
01 A aa
02 B bb
03 C ee





After importing from excel,I want to create text document
If record is exists
Status= Already exists
Else
Saved Successfully.
Textdocument:

Column1 Column2 Status
01 A Already exists
02 B Already exists
03 C Already exists
04 D Saved successfully
Try the the following code after loading the records in datagridview.

C#
string str="";
                for(int i=0;i<dataGridView1.RowCount;i++)
                {
                    for (int j = 0; j < dataGridView1.ColumnCount; j++)
                    {
                        str += dataGridView1.Rows[i].Cells[j].Value.ToString() +";";
                    }
                    str += Environment.NewLine;
                }
                System.IO.File.AppendAllText(@"d:\anand.txt", str);


Thanks,
Anand. G
 
Share this answer
 
Comments
Karthik Achari 5-Mar-14 3:46am    
Thanks for spending time to solve this problem.

I am not yet tested the code,after testing the code i can reply.
Hi Karthik Achari,
I have posted a article regarding to your requirement as you mentioned in context. The code is present in the following link.
FlatFile Database System[^]

Check the code.

Thanks & Regards,
Anand. G
 
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