We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to use opened text with a StreamReader Object

Can you let me know how I can use the currently opened text file for editing to be used in a StreamReader Object.

Here is my goal:
1.) Open the file (EditControl1.FileOpen)

2.) Read the file line by line into an array so I can check for certain text. If the text is found I place the text into a ListBox.

Problem:
1.) If I use the file just opened the StreamReader Object tells me the file is already in use and can not read it.

2.) If I close the file after it is loaded into the EditControl using EditControl1.FileOpened.Close() then the StreamReader Object works as I wrote it and my ListBox is updated with all certain text found. However now when I use the EditControl like scroll the window I get an error that states:

"ObjectDisposeException was unhandled. Make sure that you have not released a resource before attepting to use it."

thanks
teamels





3 Replies

AD Administrator Syncfusion Team November 3, 2006 12:35 AM UTC

Ok, I think I have it for the most part with a minor exception.

Here is the code I can use to use the opened file as a stream in my StreamReader Object. I just have to make sure that I do not close the reader object until I am finshed editing the file in the EditControl.

Dim reader As System.IO.StreamReader = New System.IO.StreamReader(EditControl1.FileOpened)

Problem:
With this method is that when I go to read the file in line by line the file seems to start reading several pages down the file. I mean that the first line read in using follwoing code does not read the first line in the file. It starts reading about line #200 or so. How can I force it to read the first line everytime. This seems to be some timing issue as the file is being loaded into the EditControl at the saem time I am reading it.

Dim Line as String
line = reader.readline

thanks
teamels


AD Administrator Syncfusion Team November 8, 2006 04:08 AM UTC

Ok, I want to finalize this thread for any future reference.

Steps to take to use the file just opened with another operation.
1.) Make sure the EditControl's SharedFileMode = True
either in the designer properties or in the FileLoad method.
This enables the file to be shared instead of locked out, which is the default setting.

2.) When setting up the Reader Object the correct syntax is essential. The key here is to seperate the two lines of code below instead of using the new key word on the same line as the Dim statement.

Dim reader As System.IO.StreamReader
reader = New System.IO.StreamReader(EditControl1.FileName)

Not sure why that made the difference, but it did. Now you can use the reader object to read the file for any other valid operation.


thanks
teamels


AD Administrator Syncfusion Team November 9, 2006 06:21 AM UTC

Hi Teamels,

Thanks for the update. We are glad that your problem has been solved. Please feel free to contact us if you have any other concerns.

Thanks for your patience.

Regards,
Manohari.R

Loader.
Live Chat Icon For mobile
Up arrow icon