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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use opened text with a StreamReader Object

Thread ID:





51281 Nov 1,2006 10:23 PM UTC Nov 9,2006 06:21 AM UTC WinForms 3
Tags: EditControl
Ernie Obregon
Asked On November 1, 2006 10:23 PM UTC

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.

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."


Administrator [Syncfusion]
Replied On 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)

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


Administrator [Syncfusion]
Replied On 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.


Administrator [Syncfusion]
Replied On 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.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon