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
0 OriginalGriff 339
1 Sergey Alexandrovich Kryukov 119
2 DineshMaind 113
3 majid torfi 75
4 ChauhanAjay 73
0 Sergey Alexandrovich Kryukov 9,192
1 OriginalGriff 8,405
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,938


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
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