473,788 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process File in Chunks - StreamReader

das
I posted this on ado.net, which seems like the wrong group - so here it
goes!

Hi All,
I want to process a file in chunks, meaning I have a big file of
50K rows. I want to process 5K rows at a time.

I am using StreamReader object and looping through each row and process

it, and as I process it I create an XML file and send it to DB to be
processed.
while(oSR.Peek( ) > -1)
{
// 1. Create Xml from these lines
}
// 2. Call DB Functions.

How do I read only certain number of lines at a time, complete my steps

1 and 2 and come back and read another 5K lines and so on....
any ideas gurus?
thanks

Mar 9 '06 #1
2 3385
This is kind of hokey, and untested, but should give the idea:
StringBuilder sb=null;
while(oSR.Peek( ) > -1)
{
sb=new StringBuilder() ;
for(int i=0;i<5000;i++)
{
if(oSr.Peek()>0-1)
sb.Append(oSR.R eadLine());

}
ProcessMyXml(sb .ToString();)

}

-- where ProcessMyXml accepts the string containing the 5000 lines,
you can Split ('\r') on the newline to get into a string[] array for
processing.
and Split again on each row if it has delimited info in it.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"das" wrote:
I posted this on ado.net, which seems like the wrong group - so here it
goes!

Hi All,
I want to process a file in chunks, meaning I have a big file of
50K rows. I want to process 5K rows at a time.

I am using StreamReader object and looping through each row and process

it, and as I process it I create an XML file and send it to DB to be
processed.
while(oSR.Peek( ) > -1)
{
// 1. Create Xml from these lines
}
// 2. Call DB Functions.

How do I read only certain number of lines at a time, complete my steps

1 and 2 and come back and read another 5K lines and so on....
any ideas gurus?
thanks

Mar 9 '06 #2
das
thank you, I will test this and reply back.

Mar 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
10869
by: TJ | last post by:
I am very new to C# (this is my first real project), therefore please be patient if my question is considered being to newbie. I am modifying a program which takes a text file, does some formatting then outputs the resulting file. What I am trying to do is have the program make as many files as is needed, each limited to a given file size (in this case 240KB).
2
2898
by: fabrizio.viggiani | last post by:
I try to open a file that is opened and used by win32service for logging purposes in c# The following code line StreamReader sr = new StreamReader(filename); gets an exception: The process cannot access the file 'XX' because it is being used by another process.
6
3945
by: BenSimmons | last post by:
Hi i'm creating a program that reads various log files from another program (Find-a-Drug DC project). The problem is, when I read some of the logs I get the error This process cannot access the file"C:\...." because it is being used by another process Well I know that :) as it's the log files for a constantly running DC program. The code below is what I'm using.
15
1452
by: jcrouse | last post by:
Here is my code: Dim sw As StreamWriter = File.CreateText(Application.StartupPath & "\mameversion.bat") sw.WriteLine(lblMameExePath.Text & " -help >""" & Application.StartupPath & "\mameversion.txt""") sw.Close()
14
23276
by: mesterak | last post by:
I want to very quickly count the number of lines in text files without having to read each line and increment a counter. I am working in VB.NET and C#. Does anyone have a very fast example on how to do this? Thanks, Matt
13
11155
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it writes a specific string to the log file. My original program (MKS Toolkit shell program) which keeps running "grep" checking the "exit string" on the "log files". There are no file sharing problem.
9
18889
by: Eran.Yasso | last post by:
Hi, My app starts process. Some times this process exits because of exception. Can my app know if the process exited due to exception or gracefully? In both ways, the exit code of this process is zero. I tried using the following, but it goes to catch.
28
4946
by: Jon Davis | last post by:
We're looking at running a memory-intensive process for a web site as a Windows service in isolation of IIS because IIS refuses to consume all of the available physical RAM. Considering remoting to move data in and out of this process. Need something that's quick and dirty and easy to implement, but that's performant and secure at the same time. Any suggestions / tutorials? Would prefer not to go on the TCP/IP stack (socket) as it is not...
5
2222
by: =?Utf-8?B?V2lsbGlhbSBGb3N0ZXI=?= | last post by:
Good evening all, I am trying to write a process that uses a while loop to cycle multiple files from an array throught the StreamReader Process. The whole thing works using: Dim Import_File_Reader As System.IO.StreamReader While ...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.