Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
hello
 
I want to create a button to save the .txt and , write what i've wrote in the source code
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
bw.Write("hi helo code project blabla etc");
but , what If I want many lines
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 23-Nov-12 3:00am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes - add a "\n" wherever you want a new line:
bw.Write("hi\nhelo\ncode project\nblabla\netc");
Will produce:
hi
helo
code project 
blabla
etc
  Permalink  
Comments
Phoenix 1337 at 23-Nov-12 9:11am
   
It works :$ Thanks :)
OriginalGriff at 23-Nov-12 9:15am
   
You're welcome!
Monjurul Habib at 23-Nov-12 15:52pm
   
5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
bw.Write(@"Hello
code project
blabla
etc");
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 390
1 Shai Vashdi 349
2 Sergey Alexandrovich Kryukov 325
3 OriginalGriff 265
4 Peter Leow 171
0 Sergey Alexandrovich Kryukov 8,979
1 OriginalGriff 5,280
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid