Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
i create a form with two button and one richtextbox,
first button for read file and second for write and richtextbox for show text of file,
when i read the file and want to write anything,i dont know what do i must to do in streamwrite line cod,
code is:

C#
private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog op=new OpenFileDialog();
    op.Filter="Text files|*.txt";
    DialogResult dr = op.ShowDialog();
    StreamReader sr = new StreamReader(op.FileName   );
    richTextBox1.Text = sr.ReadToEnd();
    sr.Close();

}

private void button2_Click(object sender, EventArgs e)
{
    StreamWriter sr = new StreamWriter( here i dont know ??? );
    sr.WriteLine(richTextBox1.Text);

    sr.Close();

}
Posted
Updated 11-Feb-12 10:18am
v4
Comments
Sergey Alexandrovich Kryukov 11-Feb-12 16:36pm    
How anyone can tell you what should be there if you don't explain where do you want to write?
--SA
LanFanNinja 11-Feb-12 20:04pm    
You would pass in the path of the file you wanted to write the data into.

You could use the SaveFileDialog to select your save path. It works very similar to the OpenFileDialog.

Take a look at this link to get an idea of its use.
SaveFileDialog

And here is another example:

SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Filter = "Text Files|*.txt";

if (saveDialog.ShowDialog() == DialogResult.OK)
{
using (StreamWriter writer = new StreamWriter(saveDialog.FileName))
{
writer.WriteLine(richTextBox1.Text);
writer.Close();
}
}

When the saveDialog opens just choose a folder to save the file into (for example your Documents folder) then enter a file name into the "File Name" text box (any name you wish to use) and the file will be created at that location.
Wonde Tadesse 11-Feb-12 20:55pm    
Where is MSDN?

1 solution

Read this

http://www.dotnetperls.com/streamwriter[^]

Hope this helps if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.
 
Share this answer
 
Comments
goldengriff 11-Feb-12 16:24pm    
please pay attention to my question,
i don't now what write in this line:
StreamWriter sr = new StreamWriter( here i dont know ??? );
Sergey Alexandrovich Kryukov 11-Feb-12 16:38pm    
Please see my comment to your question. It looks like you totally lost, probably don't know what do you want to do.

Read you own question by yourself -- sometimes it helps.
--SA
Sergey Alexandrovich Kryukov 11-Feb-12 16:39pm    
My 5, but OP is totally lost -- none of your fault.
I would prefer to recommend:
http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx

--SA
RDBurmon 11-Feb-12 17:25pm    
Thanks SAKryukov

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