DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 6 Aug 2007 14:59:13 -0400,    posted on: microsoft.public.dotnet.framework        back       

Thread Index
  1    JerryWEC am
          2    Jesse Houwing
          3    (Walter Wang [MSFT])
          4    Cowboy \(Gregory A. Beamer\) oSpamM
          5    (Walter Wang [MSFT])


StreamWriter ?   
Hi all!

I'm creating a file using the following lines of code inside a property 
set...

If Not File.Exists(value) Then
    StreamWriter = File.CreateText(value)

    StreamWriter.Close()

End If

When I look at this file it has a blank line (maybe a newline character). 
I've been running like this for several months no problems.  It just bugged 
me that I had this extra line at the end of my log files.

Writing lines using...

StreamWriter.WriteLine("Some Text")

Now I'm trying to create an automatic clean up method to keep only the last 
max lines. (In this case i'm using 1000 lines.) However, when I get to 1001 
lines written.  I use...

Dim oldLines() as String = File.ReadAllLines(MyFileName)

And it's getting the extra blank line.  Is this normal to have an extra line 
at the end of your files using the above code???

TIA! Jerry
Date:Mon, 6 Aug 2007 14:59:13 -0400   Author:  

Re: StreamWriter ?   
Hello JerryWEC,


> Hi all!
> 
> I'm creating a file using the following lines of code inside a
> property set...
> 
> If Not File.Exists(value) Then
> StreamWriter = File.CreateText(value)
> StreamWriter.Close()
> 
> End If
> 
> When I look at this file it has a blank line (maybe a newline
> character). I've been running like this for several months no
> problems.  It just bugged me that I had this extra line at the end of
> my log files.
> 
> Writing lines using...
> 
> StreamWriter.WriteLine("Some Text")
> 
> Now I'm trying to create an automatic clean up method to keep only the
> last max lines. (In this case i'm using 1000 lines.) However, when I
> get to 1001 lines written.  I use...
> 
> Dim oldLines() as String = File.ReadAllLines(MyFileName)
> 
> And it's getting the extra blank line.  Is this normal to have an
> extra line at the end of your files using the above code???
> 
> TIA! Jerry
> 


Are you using WriteLine or Write to write the last line? Writeline always 
appends \r\n at the end (or another linefeed character based on the OS settings).
If you use Write for the last line you shouldn't get the empty line.

Easiest is probably checking if the line is empty and then just ignore it.

Jesse
Date:Mon, 6 Aug 2007 19:39:26 +0000 (UTC)   Author:  

RE: StreamWriter ?   
Thanks Jesse for your input.

Hi Jerry,

As Jesse said, using WriteLine() will always put a new line after the text. 
You can either to make sure your last log is written to the file using 
Write() or you can always use Write() and manually control when to write a 
new line to it.

Please let us know if this helps or not.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Tue, 07 Aug 2007 02:31:23 GMT   Author:  

Re: StreamWriter ?   
Write just writes, WriteLine() adds a \r\n, as Jerry mentioned. The final 
line will be null, so you can iterate through the file like so.

string line;

while (null != (line = reader.ReadLine())
{
}

As far as, is it normal? As mentioned, the \r\n is normal. You will also 
find that most ASCII files you get, from a variety of programs, use a null 
line as an endpointer. Some even use char(0), but that is another story.

-- 
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
"JerryWEC" <JerryWEC@newsgroups.nospam> wrote in message 
news:eRz6ivF2HHA.4184@TK2MSFTNGP06.phx.gbl...

> Hi all!
>
> I'm creating a file using the following lines of code inside a property 
> set...
>
> If Not File.Exists(value) Then
>    StreamWriter = File.CreateText(value)
>
>    StreamWriter.Close()
>
> End If
>
> When I look at this file it has a blank line (maybe a newline character). 
> I've been running like this for several months no problems.  It just 
> bugged me that I had this extra line at the end of my log files.
>
> Writing lines using...
>
> StreamWriter.WriteLine("Some Text")
>
> Now I'm trying to create an automatic clean up method to keep only the 
> last max lines. (In this case i'm using 1000 lines.) However, when I get 
> to 1001 lines written.  I use...
>
> Dim oldLines() as String = File.ReadAllLines(MyFileName)
>
> And it's getting the extra blank line.  Is this normal to have an extra 
> line at the end of your files using the above code???
>
> TIA! Jerry
> 
Date:Tue, 7 Aug 2007 08:14:30 -0500   Author:  

RE: StreamWriter ?   
Hi Jerry,

I'm writing to check the status of this post. Please let us know if you 
need anything else.

By the way, I just noticed you've also posted several questions in 
newsgroup dotnet.framework.setup recently. I'm not sure if you've already 
noticed that it's not a managed newsgroup. If you want replies from MSDN 
Managed Newsgroup support team, you need to choose a newsgroup from here: 
http://msdn2.microsoft.com/en-us/subscriptions/aa974230.aspx

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Mon, 13 Aug 2007 00:48:16 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us