Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

I want to create a button to save the .txt and , write what i've wrote in the source code
C#
SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Queries|*.txt";
            sfd.FileName = "blabla";
            sfd.Title = "Save Querie as";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string path = sfd.FileName;
                BinaryWriter bw = new BinaryWriter(File.Create(path));
                bw.Write(" ");
                bw.Dispose();
            }

but , bw.Write(" "); should be for 1 line
C#
bw.Write("hi helo code project blabla etc");

but , what If I want many lines
C#
bw.Write("Hello
code project
blabla
etc");

but in that case , it gives me error. because it reads that I've forgot to add "); and , started new corrupted line
Is there any thing should make it?
Posted

Yes - add a "\n" wherever you want a new line:
C#
bw.Write("hi\nhelo\ncode project\nblabla\netc");
Will produce:
hi
helo
code project 
blabla
etc
 
Share this answer
 
Comments
Phoenix 1337 23-Nov-12 9:11am    
It works :$ Thanks :)
OriginalGriff 23-Nov-12 9:15am    
You're welcome!
Monjurul Habib 23-Nov-12 15:52pm    
5+
There is a simple way to do this.
You can add the ampersand in front of your string which indicates that it is a literal including carriage returns.
C#
bw.Write(@"Hello
code project
blabla
etc");
 
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