My program firsts reads a file then writes to the file. The program used to work fine on my old XP Home OS and using Visual Studio 2003. I've since changed to XP Pro and installed Visual Studio 2005.
I now get the following error:
"The process cannot access the file "C:\Haven.dat" because it is being used by another process."
It's got something to do with Haven.dat still being in use.
The relevant code is as follows:
The error occurs at the bolded line.
As a test I made a copy of the dat file and referenced the copy in the bolded line. There was then no error so it means that the original dat file is not being closed down.
Your help would be much appreciated.
I now get the following error:
"The process cannot access the file "C:\Haven.dat" because it is being used by another process."
It's got something to do with Haven.dat still being in use.
The relevant code is as follows:
Code:
Public Function Decrypt() As Integer
Dim fsRead As FileStream
Dim encStream As CryptoStream
Dim sr As StreamReader
fsRead = New FileStream("C:\Haven.dat", FileMode.Open, FileAccess.Read)
encStream = New CryptoStream(fsRead, key.CreateDecryptor(), CryptoStreamMode.Read)
sr = New StreamReader(encStream)
fsRead.Close()
encStream.Close()
sr.Close()
fsRead.Dispose()
encStream.Dispose()
sr.Dispose()
End Function
Public Function Encrypt() As Integer
Dim fsWrite As New FileStream
Dim encStream As CryptoStream
Dim sw As StreamWriter
[B]fsWrite = New FileStream("C:\Haven.dat", FileMode.Create, FileAccess.Write)[/B]
encStream = New CryptoStream(fsWrite, key.CreateEncryptor(), CryptoStreamMode.Write)
sw = New System.IO.StreamWriter(encStream)
fsWrite.Close()
encStream.Close()
sw.Close()
fsWrite.Dispose()
encStream.Dispose()
sw.Dispose()
End Function
The error occurs at the bolded line.
As a test I made a copy of the dat file and referenced the copy in the bolded line. There was then no error so it means that the original dat file is not being closed down.
Your help would be much appreciated.