473,413 Members | 2,044 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,413 software developers and data experts.

Streamreader is holding a text file in its grip after it is closed

I am running a vbnet web application
http://localhost/passwords/passwords.aspx on windows 2000 where a text
file is read into a temporary datatable called Table1.

Here is the problematic part of my code:

Dim sr As StreamReader = New StreamReader(Filename)
Dim line As String

Do
line = sr.ReadLine()
Dim words() As String = Split(line, ",")
Row1 = Table1.NewRow()
Row1.Item("Email") = Mid(words(0), 2, Len(words(0)) -
2)
Row1.Item("Password") = Mid(words(1), 2, Len(words(1))
- 2)
Table1.Rows.Add(Row1)

Loop Until line Is Nothing
sr.Close()

A typical Filename could be C:\Inetpub\wwwroot\passwords\passwords.txt.
The problem is that after I run the program, I am not able to write
over the text file. The error message is: "There has been a sharing
violation. The source or destination file may be in use."

I do close the StreamReader with sr.Close, so what else do I have to
do?

Apr 27 '06 #1
2 1070
Have you tried to use a trace to see if the close method is getting called?
Also, try either explicitely calling the dispose method and/or ensuring that
you also set the sr object to nothing instead of waiting for garbage
collection.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"damezumari" <ja**********@gmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
I am running a vbnet web application
http://localhost/passwords/passwords.aspx on windows 2000 where a text
file is read into a temporary datatable called Table1.

Here is the problematic part of my code:

Dim sr As StreamReader = New StreamReader(Filename)
Dim line As String

Do
line = sr.ReadLine()
Dim words() As String = Split(line, ",")
Row1 = Table1.NewRow()
Row1.Item("Email") = Mid(words(0), 2, Len(words(0)) -
2)
Row1.Item("Password") = Mid(words(1), 2, Len(words(1))
- 2)
Table1.Rows.Add(Row1)

Loop Until line Is Nothing
sr.Close()

A typical Filename could be C:\Inetpub\wwwroot\passwords\passwords.txt.
The problem is that after I run the program, I am not able to write
over the text file. The error message is: "There has been a sharing
violation. The source or destination file may be in use."

I do close the StreamReader with sr.Close, so what else do I have to
do?

Apr 27 '06 #2
I added sr = Nothing after sr.Close().

That did the trick!

Thanks!!!

Apr 27 '06 #3

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

Similar topics

5
by: Andy Mee | last post by:
Hello one and all, I'm developing an Asp.NET system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split()...
4
by: | last post by:
I am receiving xml via tcp/ip and want to save it into a msmq queue. when I use the StreamReader.ReadLine() it only reads one line of the stream. but my xml could be more than 1 line. when I use...
7
by: Daniel | last post by:
I have an winform application that uses System.IO.StreamReader and Serializer.Deserialize to load some data from a file, if any error is detected in the file a new file should be written to the...
1
by: Peter | last post by:
'if you do this Dim sr As New StreamReader _(System.AppDomain.CurrentDomain.BaseDirectory& "CR.txt") ' and then loop through values while sr.peak > -1 ...... end while
1
by: Pantelis Sotiropoulos | last post by:
Greetings! I'm opening a text file with as a StreamReader. The problem is when the file is used by another user or Windows, it won't open! When I double click the file it opens it. That's...
16
by: vvenk | last post by:
Hello: When I use either one to read a Text file, I get the same result. The length of the string that the file's content has been written into is the same. However, if the file is binary,...
1
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData =...
4
by: fniles | last post by:
I am using VB.NET 2008 and StreamReader to read from a file on our server. While the file is open in this VB.NET program, another program written in VB6 at the same time trying to append to the...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.