.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

StreamReader ReadLine ... New and Improved! (Fixed Single CR/LF)

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :.NET Framework

I have been tasked with importing a large number of old log files into a database. These files came from a Unix type server and therefore have scattered Cr and Lf's throughout. Of course anyone who has ever tried to use a streamreader.ReadLine method knows this plays havoc.


My First attempt was just to do a ReadToEnd, and then use the Replace method to filter out everything but the CrLf's... this worked outstanding.... until my file sizes got too large, and then I started getting Out of Memory Issues.


According to Google, the solution was to use a BinaryReader along with it's Peek method to look Read in a Character at a time until a CrLf was found... This also worked great .... However it was extremely slow.


For example, I did a test on a 1mb file. The ReadLine method processed the file (even though incorrectly) in 8 seconds... the Binary Reader (though Correct) took 48 seconds. Doesn't sound like much but when you are looking at Gigs worth of file, it was taking hours to process just 1 CD.


... So finally to the good stuff..... I knew ReadLine was the way to go...but h

View Complete Post

More Related Resource Links

StreamReader.ReadLine(), StreamWriter.WriteLine() encoding issue


I have an ANSI text file which I read and change and write back the changes. The file originally is stored as follows:


Fine. Using StreamReader ctor without encoding parameter (which is not the same as Encoding.Default ) works fine (read+write) but the result is:

Line1<0D 0A>
Line2<0D 0A>
LineN<0D 0A>

So my question is how to force WriteLine() to write new line as 0A and not 0D 0A . Btw, when viewing a text file with 0A new lines using Notepad it is not displayed correctly. Notepad++ displays it correctly. The file does not have a BOM!

When using Encoding.UTF7 new lines are written as 0A but special characters like é is written as +AOk- which is not was I want.

The trick Write(0x0A) also not works because it will be written as characters '1' and '0' ("10" dec == 0A hex).

How to do it correctly? Many thanks!

Programming is a kind of art but not all programmers are a

Application Architecture in Windows Forms 2.0-Single-MDI Applications

Consider an MDI application like Microsoft Excel; files opened from the file system (by double-clicking) are all opened as separate child windows within the parent Excel window.7 For the first instance of an MDI application to open a new child window to display the file that was passed to the second instance of the application, the second instance must be able to communicate with the initial instance.

How to Fixed GridViews Header and Footer when scrolling in asp.net?

This article is to show you how to Fix GridView''s Header and Footer in a simple code with CSS and JavaScript

Scrollable GridView with fixed headers in asp.net C# vb.net

In this example i am going to show how to create scrollable GridView with fixed headers which don''t get scrolled with records and stay on the top in asp.net using css, I''ve tested this code on IE7 and Firefox 2.0 , 3.5.

For this we need to add css to headers of gridview to keep them on the top.

First of all place a Panel on the aspx page from thetoolbox. Set height to 200px and width to 200px
and scrollbars to Vertical.
Now add a gridview inside this Panel and set the datasource to populate gridview.

merging multiple tables in a single dataset to single table


 i have a stored procedure which returns three tables to a dataset ..... now i need to merge all three tables to a single table from d same dataset 

like dataset1 has table1 table2 and table3 .... i want all the three tabels to be merged into dataset1 itself .... instead of three diffrent tables so that i can show all three table data in a single datagrid  as a compact data and combination of 3 tables from d single dataset.....

can some1 help me please.....

how To Insert the single quotes in sqlcommand in asp.net


Hi all

    i am developed on simple user registeration application in that i gave  address field .when i am trying to enter something like this (1st main,b'lore) but wont take while inserting.

my query is

sqlcommand cmd=new sqlcommand("insert into registeration_form(name,address)values('"+txtname.text+"','"+txt_address+"')",con);

how can i pass the  quotes also to my query please if any one know reply me.


G Dinakaran

Inside Microsoft patterns & practices: Building WPF and Silverlight Applications with a Single Code


This article discusses the Project Linker tool and other techniques to create applications that target both WPF and Silverlight from a single code base.

Erwin van der Valk

MSDN Magazine August 2009

Coding Tools: Improved Support For Parallelism In The Next Version Of Visual Studio


We take a look at planned support for parallel programming for both managed and native code in the next version of Visual Studio.

Stephen Toub and Hazim Shafi

MSDN Magazine October 2008

Cutting Edge: Single-page Interface and AJAX Patterns


This month we begin a look at the Single Page Interface (SPI) model and some design patterns for designing AJAX applications.

Dino Esposito

MSDN Magazine May 2008

Single Sign-On: A Developer's Introduction To Active Directory Federation Services


Use Active Directory Federation Services to allow other organizations to use your Web applications without the need for you to grant access explicitly.

Keith Brown

MSDN Magazine November 2006

Editor's Note: New and Improved Team


We've all been subconsciously conditioned through the years to turn a skeptical eye towards claims of being "new and improved. " After all, the phrase often means that some favorite feature has been turned into a new deficiency.

MSDN Magazine June 2006

ASP.NET 2.0: Speed Up Your Site with the Improved View State in ASP.NET 2.0


View state is a wonderful thing. It allows the ASP.NET developer to maintain state for server-side controls that are not form elements.Used judiciously, it can improve the user experience. But in the wrong hands, it can cause your pages to grind to a halt. The release of ASP.NET 2.0 will include a variety of improvements to view state that will make it easier to use and less likely to slow performance.

Fritz Onion

MSDN Magazine October 2004

Windows Server 2003: Discover Improved System Info, New Kernel, Debugging, Security, and UI APIs


There's a lot to say about Windows Server 2003. First of all, it's the first operating system with built-in .NET Framework support, and it's the first 64-bit OS from Microsoft. But wait, there's more! There are lots of new features and APIs in this version as well. For instance, Windows Server 2003 features Hot Add Memory and a number of other arcane new tidbits. There are new APIs for handling threads, directories, and files, and new features like the low fragmentation heap for managing memory and system information. There's vectored exception handling and new UI APIs as well.OS internals expert Matt Pietrek takes a look at the additions he finds most interesting and useful so you'll have a good place to start when you dive into Windows Server 2003.

Matt Pietrek

MSDN Magazine June 2003

Windows CE.NET: New Version Offers Revamped Platform Builder, Improved Tools, Enhanced API, and Sour


Windows CE .NET, the newest member of the .NET family, includes a number of improvements over previous versions of Windows CE. For example, there are quite a few new APIs and enhancements to security and connectivity, the user interface, the kernel, and the emulator. In addition, DirectX support has been added and C++ in Windows CE .NET now supports C++ exceptions, STL, and runtime type information. In this article the author takes a tour of Windows CE .NET, starting with the New Platform Wizard that allows you to code for your choice of devices. A sample application is included that locates features on portable devices so the reader knows what's available before writing code.

Paul Yao

MSDN Magazine July 2002

how to set multiple button in single image


Hi friends,

I need to make multiple button in a single image in asp.net.

and need coding also for vb.net.

thanx in advance

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend