473,796 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Streamreader Alternative

I am writing an ASP page with a C# backend. This page uses a
StreamReader to input a file and pull out a specific section of the
text based on markers inside. While the code I have works, I get a 404
error on files larger than 10 mbs, which will be a common occurence. I
understand this might be a question better suited for an ASP forum, but
I was wondering if anyone out there knows of an alternative to the
StreamReader which will help me avoid this timout issue.

Thanks.

Aug 14 '06 #1
9 5597
Matt Bailey <ba*********@gm ail.comwrote:
I am writing an ASP page with a C# backend. This page uses a
StreamReader to input a file and pull out a specific section of the
text based on markers inside. While the code I have works, I get a 404
error on files larger than 10 mbs, which will be a common occurence. I
understand this might be a question better suited for an ASP forum, but
I was wondering if anyone out there knows of an alternative to the
StreamReader which will help me avoid this timout issue.
I doubt that the issue is really with StreamReader - that's pretty
fast.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 14 '06 #2
StreamReader itself should be quite capable of handling the file. How are
you parsing the file? Reading line by line? Reading the whole thing at
once? How are you then "separating " out the section you need?

Also, just to clarify - you say you are getting a 404 error. That is a
"Page Not Found" error, I don't believe a timeout would throw this...

--
Adam Clauss

"Matt Bailey" <ba*********@gm ail.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
>I am writing an ASP page with a C# backend. This page uses a
StreamReader to input a file and pull out a specific section of the
text based on markers inside. While the code I have works, I get a 404
error on files larger than 10 mbs, which will be a common occurence. I
understand this might be a question better suited for an ASP forum, but
I was wondering if anyone out there knows of an alternative to the
StreamReader which will help me avoid this timout issue.

Thanks.

Aug 14 '06 #3
Here is a snippit of the code...

private Hashtable readPDFile(stri ng pdFile)
{
StreamReader reader = new StreamReader(Fi le.OpenRead(pdF ile));
Hashtable pdList = new Hashtable();

while (reader.ReadLin e().Trim() != "NCE"){}

ArrayList entries = new ArrayList();
string entry;

entry = reader.ReadLine ();

while(entry != "ZZZZ")
{
if(!entry.Start sWith("&"))
entries.Add(ent ry.Substring(0, 8));

entry = reader.ReadLine ().Trim();
}

entries.Sort();

foreach(object o in entries)
{
string key = o.ToString().Su bstring(0, 7);

if(pdList.Conta insKey(key))
pdList[key] = Convert.ToInt32 (pdList[key]) + 1;
else
pdList.Add(key, 1);
}

reader.Close();

return pdList;
}

Essentially, I am reading through a file which is seperated into
"chapters", which are denoted by headers. The section I want starts
with the header "NCE", so I am reading through the lines until I hit
that marker, and then read from the file until I hit the end of the
chapter, marked by "ZZZZ". From there, I parse through the list and
count the number of entries for each value, ignoring the final
character. In the example of the file that doesn't work, that is about
20,000 records, which this program can handle. The problem lies in
where the file itself contains more data further on in additional
chapters, which is padding the filesize to 10 mb. This code works with
smaller files with more records being read in (approx 30,000), so I
know it's the additional chapters that are the culprit.

And you are right, I am not getting a 404 error, but a "The page cannot
be displayed. The page you are looking for is currently unavailable.
The Web site might be experiencing technical difficulties, or you may
need to adjust your browser settings." error.

Hope this makes things clearer.

Thanks!

Adam Clauss wrote:
StreamReader itself should be quite capable of handling the file. How are
you parsing the file? Reading line by line? Reading the whole thing at
once? How are you then "separating " out the section you need?

Also, just to clarify - you say you are getting a 404 error. That is a
"Page Not Found" error, I don't believe a timeout would throw this...

--
Adam Clauss

"Matt Bailey" <ba*********@gm ail.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
I am writing an ASP page with a C# backend. This page uses a
StreamReader to input a file and pull out a specific section of the
text based on markers inside. While the code I have works, I get a 404
error on files larger than 10 mbs, which will be a common occurence. I
understand this might be a question better suited for an ASP forum, but
I was wondering if anyone out there knows of an alternative to the
StreamReader which will help me avoid this timout issue.

Thanks.
Aug 14 '06 #4
You might want to try turning off page buffering in your ASP.NET page
to see if that helps. It's turned on by default, and a 10Mb file will
likely be over that threshold.

Jono

Matt Bailey wrote:
Here is a snippit of the code...

private Hashtable readPDFile(stri ng pdFile)
{
StreamReader reader = new StreamReader(Fi le.OpenRead(pdF ile));
Hashtable pdList = new Hashtable();

while (reader.ReadLin e().Trim() != "NCE"){}

ArrayList entries = new ArrayList();
string entry;

entry = reader.ReadLine ();

while(entry != "ZZZZ")
{
if(!entry.Start sWith("&"))
entries.Add(ent ry.Substring(0, 8));

entry = reader.ReadLine ().Trim();
}

entries.Sort();

foreach(object o in entries)
{
string key = o.ToString().Su bstring(0, 7);

if(pdList.Conta insKey(key))
pdList[key] = Convert.ToInt32 (pdList[key]) + 1;
else
pdList.Add(key, 1);
}

reader.Close();

return pdList;
}

Essentially, I am reading through a file which is seperated into
"chapters", which are denoted by headers. The section I want starts
with the header "NCE", so I am reading through the lines until I hit
that marker, and then read from the file until I hit the end of the
chapter, marked by "ZZZZ". From there, I parse through the list and
count the number of entries for each value, ignoring the final
character. In the example of the file that doesn't work, that is about
20,000 records, which this program can handle. The problem lies in
where the file itself contains more data further on in additional
chapters, which is padding the filesize to 10 mb. This code works with
smaller files with more records being read in (approx 30,000), so I
know it's the additional chapters that are the culprit.

And you are right, I am not getting a 404 error, but a "The page cannot
be displayed. The page you are looking for is currently unavailable.
The Web site might be experiencing technical difficulties, or you may
need to adjust your browser settings." error.

Hope this makes things clearer.

Thanks!

Adam Clauss wrote:
StreamReader itself should be quite capable of handling the file. How are
you parsing the file? Reading line by line? Reading the whole thing at
once? How are you then "separating " out the section you need?

Also, just to clarify - you say you are getting a 404 error. That is a
"Page Not Found" error, I don't believe a timeout would throw this...

--
Adam Clauss

"Matt Bailey" <ba*********@gm ail.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
>I am writing an ASP page with a C# backend. This page uses a
StreamReader to input a file and pull out a specific section of the
text based on markers inside. While the code I have works, I get a 404
error on files larger than 10 mbs, which will be a common occurence. I
understand this might be a question better suited for an ASP forum, but
I was wondering if anyone out there knows of an alternative to the
StreamReader which will help me avoid this timout issue.
>
Thanks.
>
Aug 14 '06 #5
Matt Bailey <ba*********@gm ail.comwrote:
Here is a snippit of the code...
Rather than a snippet, have you tried producing a short but complete
program which demonstrates the problem? What happens if you try to call
the same method from a console app which just passes in the filename
from the command line?

A few pointers on the code, btw:

1) You're not using either a "using" statement or try/finally with the
StreamReader, so if anything goes wrong the file will stay open until
the GC kicks in and finalizes the underlying stream.

2) Your ToString call in the foreach is unnecessary - just declare o as
a string instead of as an object.

3) It's not clear why you're building a list in the first place - why
not just add them straight to the hashtable?

Finally, if you can't reproduce the problem in a console app, add some
logging to the method to see how far it's actually getting and how long
it's taking to get there.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 14 '06 #6
Hi Jon, thanks for the replies.

The reason I am going to a list is so that I can sort the entries. The
Hashtable doesn't have that functionality as far as I know. As for the
try/catch, it's there, but not in the snippet. The code works in a
console app, but not over the web, which is where my problem lies.

Jon wrote:
Matt Bailey <ba*********@gm ail.comwrote:
Here is a snippit of the code...

Rather than a snippet, have you tried producing a short but complete
program which demonstrates the problem? What happens if you try to call
the same method from a console app which just passes in the filename
from the command line?

A few pointers on the code, btw:

1) You're not using either a "using" statement or try/finally with the
StreamReader, so if anything goes wrong the file will stay open until
the GC kicks in and finalizes the underlying stream.

2) Your ToString call in the foreach is unnecessary - just declare o as
a string instead of as an object.

3) It's not clear why you're building a list in the first place - why
not just add them straight to the hashtable?

Finally, if you can't reproduce the problem in a console app, add some
logging to the method to see how far it's actually getting and how long
it's taking to get there.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 15 '06 #7
I also neglected to mention in the previous post that I have tried to
do some debugging using both logging and breakpoints in the code, and
they never go off....

Aug 15 '06 #8
And in response to Jono, I have tried setting the Page.Response.B uffer
equal to false, assuming that's the buffer you are refering to. That
is to no avail.

Aug 15 '06 #9
Matt Bailey wrote:
I also neglected to mention in the previous post that I have tried to
do some debugging using both logging and breakpoints in the code, and
they never go off....
That's the first thing to fix then. You say it's working for small
files - so you should be able to get logging etc working on small
files. You can then try with the large file.

My guess is that you'll find your problem isn't in the area you think
it is.

Jon

Aug 15 '06 #10

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

Similar topics

9
12776
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: "<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>" HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
2
13005
by: Keith Kingsley | last post by:
I'm using a StreamReader to read in several lines from an ASCII file. I'd like to know the StreamReader's "true" position-- that is, the number of bytes into the file that the StreamReader has read. I thought about using MyStreamReader.BaseStream.Position, but this always seems to return a multiple of the StreamReader's buffer size (which seems natural-- as I understand it the StreamReader reads from the underlying stream in discrete...
3
5022
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A typical response in this protocol would be:
2
381
by: Ian Oldbury | last post by:
I'm having a problem reading from a flat file, in the file "£" and "»" exist however when i view the contents of the variable LineContents these characters don't exist. Has anyone got any suggestions???? Dim LineContents as string Dim fs As FileStream
1
2874
by: Matt Bailey | last post by:
Hi, I have an ASPX page with a C# backend in which I use a StreamReader to input a file so that I can parse through it. While the code I have works, I get a 404 error when I try to use an input file larger that 10 mb, which will be a common occurance for my app. Is there a way I can increase the time on the timeout, or is there an alternative to the streamreader that I can use? Any help is greatly appreciated.
3
3113
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1) Response.Write(sReader.ReadLine) End While as well as using the FileStream object along with the StreamReader object like this:
1
1984
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on this. It is the part of the Streamreader class that creates a StreamReader instance for a given Stream. The next entry however I don't understand: - Public Fields Name Description Null A StreamReader object around an empty stream.
1
2878
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData = streamReader.ReadToEnd(); I'm using System.Text.Encoding.Default so that I can get some swedish characters working. But I'm having problem when reading a xml-file that's encoded with UTF-8. In the beginning of the xml-files you have the encoding for the...
0
2362
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all possibilities of calling the streamreader, but nothing worked. Dim sr As StreamReader = New StreamReader(Filename, System.Text.Encoding.Default, True) Dim sr As StreamReader = New StreamReader(Filename, _System.Text.Encoding.ASCII, False, 512)
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
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...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
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,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4119
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
3
2927
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.