Re: Streamreader Alternative

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Here is a snippit of the code...

private Hashtable readPDFile(string pdFile)
{
StreamReader reader = new StreamReader(File.OpenRead(pdFile));
Hashtable pdList = new Hashtable();

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

ArrayList entries = new ArrayList();
string entry;

entry = reader.ReadLine();

while(entry != "ZZZZ")
{
if(!entry.StartsWith("&"))
entries.Add(entry.Substring(0, 8));

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

entries.Sort();

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

if(pdList.ContainsKey(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" <bailey.matt@xxxxxxxxx> wrote in message
news:1155587329.568400.83210@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.


.



Relevant Pages

  • Re: Streamreader Alternative
    ... ArrayList entries = new ArrayList; ... entry = reader.ReadLine; ... I am reading through a file which is seperated into ... StreamReader to input a file and pull out a specific section of the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Writing multilingual site - how to effectively output strings depending on language
    ... Reading a file of 1000 entries into memory so that each entry can be read from memory. ...
    (comp.lang.php)
  • Re: Read txt File to a DataSet
    ... Good article on reading a comma delimited file using StreamReader. ... > Suresh. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Fastest way to read a file
    ... > Try to limit reading ... Using FileStream, the same kind of operation on a ... >> StreamReader ReadLine) wheras StreamReader would have taken 1m 30secs. ... >>> Happy coding! ...
    (microsoft.public.dotnet.languages.csharp)
  • StreamReader.Close() response is very slow - please help
    ... I am interested in reading the text of a web page and parsing it. ... StreamReader SR = new StreamReader; ... fact I parse the data and desire to terminate loading because the ...
    (microsoft.public.dotnet.languages.csharp)