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

D

damezumari

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?
 
M

Mark Fitzpatrick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top