473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

file I/O

Inorder to handle large files over 100 MB, is there a way in dotnet to open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.
Jul 21 '05 #1
10 1585
I don't think there is any different between opening a 1M file or 100M file
if you use a stream. Streams are designed with buffers and will only read
in as much information as you want. So, you could open your file using
FileStream and seek to a specified location, then read as many bytes as you
want.

Now, if you need more complex processing like getting the 200th row of some
file that are delimited by newlines, then that is something that you might
have to process yourself or rely on something like a Stream reader.
"shiva" <sh***@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
Inorder to handle large files over 100 MB, is there a way in dotnet to
open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.

Jul 21 '05 #2
Thank you for the feedback Sir. Well, i am just trying to print a 30MB file
and its shaky. It gets hogged sometimes amd prints sometimes as if it works
when we have luck. Unless or otherwise something is wrong with the following
code. There is lot more transactions to do than just printing, but it is
skaky right here when printing.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Open a file for reading
Dim FILENAME As String
Dim FileContents As String
Dim iCount As Integer
iCount = 1

FILENAME = "c:\\Filereader\\File1.txt"

Try

'Get a StreamReader class that can be used to read the file
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(FILENAME)

'Read Line By Line
While True
FileContents = CType(objStreamReader.ReadLine, String)
If Not FileContents = Nothing Then
Response.Write(iCount & "Begin Line1" & "<br>")
Response.Write(FileContents)
Response.Write("<br>" & iCount & "End Line1" & "<br>")
iCount = iCount + 1
'lblRawOutput.Text &= FileContents & vbCrLf
Else : Exit While
End If
End While

'Set the text of the file to a Web control
'lblRawOutput.Text = contents

objStreamReader.Close()

Catch ex As Exception
Response.Write(ex.Message)
End Try

End Sub

"Peter Rilling" wrote:
I don't think there is any different between opening a 1M file or 100M file
if you use a stream. Streams are designed with buffers and will only read
in as much information as you want. So, you could open your file using
FileStream and seek to a specified location, then read as many bytes as you
want.

Now, if you need more complex processing like getting the 200th row of some
file that are delimited by newlines, then that is something that you might
have to process yourself or rely on something like a Stream reader.
"shiva" <sh***@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
Inorder to handle large files over 100 MB, is there a way in dotnet to
open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.


Jul 21 '05 #3
Thank you for the feedback Sir. Well, i am just trying to print a 30MB file
and its shaky. It gets hogged sometimes amd prints sometimes as if it works
when we have luck. Unless or otherwise something is wrong with the following
code. There is lot more transactions to do than just printing, but it is
skaky right here when printing.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As
  2. System.EventArgs) Handles Button1.Click
  3. 'Open a file for reading
  4. Dim FILENAME As String
  5. Dim FileContents As String
  6. Dim iCount As Integer
  7. iCount = 1
  8.  
  9. FILENAME = "c:\\Filereader\\File1.txt"
  10.  
  11. Try
  12.  
  13. 'Get a StreamReader class that can be used to read the file
  14. Dim objStreamReader As StreamReader
  15. objStreamReader = File.OpenText(FILENAME)
  16.  
  17. 'Read Line By Line
  18. While True
  19. FileContents = CType(objStreamReader.ReadLine, String)
  20. If Not FileContents = Nothing Then
  21. Response.Write(iCount & "Begin Line1" & "<br>")
  22. Response.Write(FileContents)
  23. Response.Write("<br>" & iCount & "End Line1" & "<br>")
  24. iCount = iCount + 1
  25. 'lblRawOutput.Text &= FileContents & vbCrLf
  26. Else : Exit While
  27. End If
  28. End While
  29.  
  30. 'Set the text of the file to a Web control
  31. 'lblRawOutput.Text = contents
  32.  
  33. objStreamReader.Close()
  34.  
  35. Catch ex As Exception
  36. Response.Write(ex.Message)
  37. End Try
  38.  
  39. End Sub
  40.  
  41.  
"Peter Rilling" wrote:
I don't think there is any different between opening a 1M file or 100M file
if you use a stream. Streams are designed with buffers and will only read
in as much information as you want. So, you could open your file using
FileStream and seek to a specified location, then read as many bytes as you
want.

Now, if you need more complex processing like getting the 200th row of some
file that are delimited by newlines, then that is something that you might
have to process yourself or rely on something like a Stream reader.
"shiva" <sh***@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
Inorder to handle large files over 100 MB, is there a way in dotnet to
open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.


Jul 21 '05 #4
Thank you for the feedback Sir. Well, i am just trying to print a 30MB file
and its shaky. It gets hogged sometimes amd prints sometimes as if it works
when we have luck. Unless or otherwise something is wrong with the following
code. There is lot more transactions to do than just printing, but it is
skaky right here when printing.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As
  2. System.EventArgs) Handles Button1.Click
  3. 'Open a file for reading
  4. Dim FILENAME As String
  5. Dim FileContents As String
  6. Dim iCount As Integer
  7. iCount = 1
  8.  
  9. FILENAME = "c:\\Filereader\\File1.txt"
  10.  
  11. Try
  12.  
  13. 'Get a StreamReader class that can be used to read the file
  14. Dim objStreamReader As StreamReader
  15. objStreamReader = File.OpenText(FILENAME)
  16.  
  17. 'Read Line By Line
  18. While True
  19. FileContents = CType(objStreamReader.ReadLine, String)
  20. If Not FileContents = Nothing Then
  21. Response.Write(iCount & "Begin Line1" & "<br>")
  22. Response.Write(FileContents)
  23. Response.Write("<br>" & iCount & "End Line1" & "<br>")
  24. iCount = iCount + 1
  25. 'lblRawOutput.Text &= FileContents & vbCrLf
  26. Else : Exit While
  27. End If
  28. End While
  29.  
  30. 'Set the text of the file to a Web control
  31. 'lblRawOutput.Text = contents
  32.  
  33. objStreamReader.Close()
  34.  
  35. Catch ex As Exception
  36. Response.Write(ex.Message)
  37. End Try
  38.  
  39. End Sub
  40.  
  41.  
"Peter Rilling" wrote:
I don't think there is any different between opening a 1M file or 100M file
if you use a stream. Streams are designed with buffers and will only read
in as much information as you want. So, you could open your file using
FileStream and seek to a specified location, then read as many bytes as you
want.

Now, if you need more complex processing like getting the 200th row of some
file that are delimited by newlines, then that is something that you might
have to process yourself or rely on something like a Stream reader.
"shiva" <sh***@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
Inorder to handle large files over 100 MB, is there a way in dotnet to
open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.


Jul 21 '05 #5
Shiva,

Are you sure you want it byte by byte, used are often Unicodecharters which
used two bytes.

Than the encoding class will probably one of the first things too look at.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps?

Copr
"shiva" <sh***@discussions.microsoft.com>
Inorder to handle large files over 100 MB, is there a way in dotnet to open only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.

Jul 21 '05 #6
Shiva,

Tell us first what type of file it is, text, a kind of own database, are
there char in it etc. or maybe it are pictures. Now it is just shooting in
the dark.
Cor
Jul 21 '05 #7
"shiva" <sh***@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...
Thank you for the feedback Sir. Well, i am just trying to print
a 30MB file
and its shaky. It gets hogged sometimes amd prints sometimes as
if it works
when we have luck. Unless or otherwise something is wrong with
the following
code. There is lot more transactions to do than just printing,
but it is
skaky right here when printing.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Open a file for reading
Dim FILENAME As String
Dim FileContents As String
Dim iCount As Integer
iCount = 1

FILENAME = "c:\\Filereader\\File1.txt"

Try

'Get a StreamReader class that can be used to read
the file
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(FILENAME)

'Read Line By Line
While True
FileContents = CType(objStreamReader.ReadLine,
String)
ReadLine returns a string already, so there is no reason to
re-caste it.
If Not FileContents = Nothing Then
Response.Write(iCount & "Begin Line1" &
"<br>")
Response.Write(FileContents)
Response.Write("<br>" & iCount & "End Line1"
& "<br>")
iCount = iCount + 1
'lblRawOutput.Text &= FileContents & vbCrLf
Else : Exit While
End If
End While


It doesn't look like your speed issues are due to the way you are
working with the files, but rather with what you are doing with
all the data.

What is this Response object you are working with? I'm assuming
it's something like a web response. If this is the case then it
can take quite a while to send the 30 MB of data via the network.
Even on a local network it can take a while depending on network
configuration and current traffic loads.

Also you have
'lblRawOutput.Text &= FileContents & vbCrLf
commented out. However, if your tests were done with this
uncommented it could have a drastic performance hit for large
files, as the larger a string gets, the longer it takes to
concatenate more data on to the end of it.

Andrew Faust
Jul 21 '05 #8

"shiva" <sh***@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
Dear Cor,

For example if the file is a 30MB file, i am looking for
opening for 1MB
at a time.


You can't open only 1 MB at a time. You either have a file open
or you don't. Size is irrelevant. However, you can read in to
memory only a small portion at a time.

Andrew Faust
Jul 21 '05 #9
Shiva,

What is than the reason you do than not proces it line by line?

http://msdn.microsoft.com/library/de...xtFromFile.asp

Cor

"shiva" <sh***@discussions.microsoft.com> schreef in bericht
news:9D**********************************@microsof t.com...
Hi Cor,

Its a regular text file, but the formats are pretty complex like a EDI file. There are no pictures or any kind of picture data in the file. Its a
regular file

Header1<Information>endofline
Detail1<Information>endofline
Detail2<Information>endofline
Header2<Information>endofline
Detail1<Information>endofline
Detail2<Information>endofline
Detail3<Information>endofline
Header3<Information>endofline
Detail1<Information>endofline
Header4<Information>endofline
Detail1<Information>endofline
Detail2<Information>endofline
Detail3<Information>endofline

I understand if i read only a 1MB out of the 30MB i may not get an entire
record, but i can come up with some other algorithm for that.

But the main question is, is there a way i can open 1MB out of the 30MB.

Thank you
Shiva
"Cor Ligthert" wrote:
Shiva,

Tell us first what type of file it is, text, a kind of own database, are
there char in it etc. or maybe it are pictures. Now it is just shooting in the dark.
Cor

Jul 21 '05 #10
Shiva,

When you process it line by line why it can than not be in a kind of pseudo
Private rowcounter = 0

Process 10000rows(not endoffile)

Procedure Process10000rows
do while not endoffile
For rowcounter to 10000
read line into whatever
next

When this can fit and you cannot make this in real code tell than?

Cor

"shiva" <sh***@discussions.microsoft.com>
Dear Cor,

The reason i don't want to do line by line was it runs out of memory.

Dear Andrew,

I removed the Ctype and the Response.write but the difference in
performance is very less.

Thank you
Siva
"Cor Ligthert" wrote:
Shiva,

What is than the reason you do than not proces it line by line?

http://msdn.microsoft.com/library/de...xtFromFile.asp
Cor

"shiva" <sh***@discussions.microsoft.com> schreef in bericht
news:9D**********************************@microsof t.com...
Hi Cor,

Its a regular text file, but the formats are pretty complex like a EDI
file.
There are no pictures or any kind of picture data in the file. Its a
regular file

Header1<Information>endofline
Detail1<Information>endofline
Detail2<Information>endofline
Header2<Information>endofline
Detail1<Information>endofline
Detail2<Information>endofline
Detail3<Information>endofline
Header3<Information>endofline
Detail1<Information>endofline
Header4<Information>endofline
Detail1<Information>endofline
Detail2<Information>endofline
Detail3<Information>endofline

I understand if i read only a 1MB out of the 30MB i may not get an
entire record, but i can come up with some other algorithm for that.

But the main question is, is there a way i can open 1MB out of the 30MB.
Thank you
Shiva
"Cor Ligthert" wrote:

> Shiva,
>
> Tell us first what type of file it is, text, a kind of own database, are > there char in it etc. or maybe it are pictures. Now it is just

shooting in
> the dark.
>
>
> Cor
>
>
>


Jul 21 '05 #11

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

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
0
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.