Directory / File IO / Registry Topics include: IO, file system and the registry

Go Back  Xtreme .NET Talk > .NET > Directory / File IO / Registry > [VB.NET] Problem with carriage returns when writing to text files.


Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2004, 05:39 AM
Bob Burke Bob Burke is offline
Newcomer

Preferred language:
VB.NET
 
Join Date: Apr 2004
Location: Dublin, Ireland
Posts: 4
Bob Burke is on a distinguished road
Question [VB.NET] Problem with carriage returns when writing to text files.



Code:
Private Sub butSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butSave.Click
        Dim save As New SaveFileDialog()
        save.Title = "Save Domain List As Text File"
        save.Filter = "Text files (*.txt)|*.txt"
        save.FilterIndex = 0
        save.RestoreDirectory = True
        If save.ShowDialog = DialogResult.OK Then
            Dim contents As String
            Dim FS As FileStream = save.OpenFile
            Dim SW As New StreamWriter(FS, System.Text.Encoding.ASCII)
            contents = txtResults.Text()
            contents.Replace(vbCrLf, System.Environment.NewLine)
            SW.Write(contents)
            SW.Close()
            FS.Close()
        End If
    End Sub
This the code I am using to write contents (which is the contents of a multiline textbox named txtResults) to a text file. When I view the textfile in Wordpad or Editplus it is fine but in Notepad all off the data is on one line and is seperated by glyphs... i.e. no carriage returns.

I really need to be able to view this in Notepad and I'm also wondering why I can't? Can anyone give me any pointers or workarounds?

Thanks a lot.
~Bob
Reply With Quote
  #2  
Old 04-05-2004, 07:32 AM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is online now
Ultimate Contributor

Preferred language:
C#, VB
 
Join Date: Sep 2002
Location: Lancashire, UK
Posts: 6,462
PlausiblyDamp is on a distinguished road
Default

what happens if you remove the line
Code:
contents.Replace(vbCrLf, System.Environment.NewLine)
Reply With Quote
  #3  
Old 04-05-2004, 08:04 AM
Bob Burke Bob Burke is offline
Newcomer

Preferred language:
VB.NET
 
Join Date: Apr 2004
Location: Dublin, Ireland
Posts: 4
Bob Burke is on a distinguished road
Default

Same output as before, all of the data on one line seperated by glyphs.

EDIT: Eek!! I had been using a rich text box instead of a normal text box... I had originally used a rich text box instead of a normal text box because I couldn't figure out how to get a normal text box to accept multiple lines. Sorry guys!

Last edited by Bob Burke; 04-05-2004 at 08:10 AM.
Reply With Quote
  #4  
Old 04-05-2004, 08:46 AM
Hamburger1984 Hamburger1984 is offline
Centurion

Preferred language:
C#!!!!
 
Join Date: Jun 2003
Location: Hamburg,Germany
Posts: 162
Hamburger1984 is on a distinguished road
Default

Quote:
Originally Posted by PlausiblyDamp
what happens if you remove the line
Code:
contents.Replace(vbCrLf, System.Environment.NewLine)
...maybe it's the same dumb mistake I made some times.. try this:

Code:
contents = contents.Replace(vbCrLf, System.Environment.NewLine)

Hope this helps!

Andreas
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Carriage return problem in ASP.NET andycharger ASP.NET 3 05-11-2010 04:37 AM
carriage return in VB.Net eramgarden General 4 10-06-2006 01:40 PM
Querying NText fields returns <long text> samsmithnz Database / XML / Reporting 4 08-19-2005 10:40 AM
how do i put carriage returns in a string? joeybagadonutz General 8 03-27-2004 09:11 AM
Preserving carriage returns in a label burak ASP.NET 4 10-01-2003 09:57 AM

Advertisement:







Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe