Click here to Skip to main content
12,942,930 members (59,292 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 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  
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 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+

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,633
CHill60 2,880
Maciej Los 2,268
Jochen Arndt 1,900
ppolymorphe 1,755


Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100