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.
Unfortunately, activation email could not send to your email. Please try again.

How to use opened text with a StreamReader Object

Thread ID:

Created:

Updated:

Platform:

Replies:

51281 Nov 1,2006 05:23 PM Nov 9,2006 01:21 AM Windows Forms 3
loading
Tags: EditControl
Ernie Obregon
Asked On November 1, 2006 05:23 PM

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





Administrator [Syncfusion]
Replied On November 2, 2006 07:35 PM

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

Administrator [Syncfusion]
Replied On November 7, 2006 11:08 PM

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

Administrator [Syncfusion]
Replied On November 9, 2006 01:21 AM

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

CONFIRMATION

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.

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.

;