469,591 Members | 1,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,591 developers. It's quick & easy.

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 978
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by | last post: by
1 post views Thread by Peter | last post: by
1 post views Thread by Pantelis Sotiropoulos | last post: by
1 post views Thread by Sladan | last post: by
4 posts views Thread by fniles | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.