EDN Admin
Well-known member
Hi everyone, Im trying to write text to / read text from a file, but when its trying to execute the My.Computer.FileSystem.WriteAllText code, it throws an exception: "The process cannot access to the file "<filename>" because its
being used by another process", and the "source" of the exception is "mscorlib"
Note: this is a DLL file, which is being used by an application.
I tried to use:
If IO.File.Exists(My.Application.Info.DirectoryPath & "Sites_int.wblist") = True Then<br/>
Kill(My.Application.Info.DirectoryPath & "Sites_int.wblist")<br/>
End If<br/>
IO.File.WriteAllText(My.Application.Info.DirectoryPath & "Sites.wblist", FullString)<br/>
Catch ex As Exception<br/>
MsgBox("An error has occoured:" & vbNewLine & ex.Message & vbNewLine & ex.Source, MsgBoxStyle.Critical, "Error")<br/>
End Try
And when I try to read it:
SList = IO.File.ReadAllLines(My.Application.Info.DirectoryPath & "Sites_int.wblist").ToList
I tried to set permissions:
Dim Permission As New System.Security.Permissions.FileIOPermission(Security.Permissions.PermissionState.Unrestricted, My.Application.Info.DirectoryPath & "MyDLL.dll")<br/>
Permission.AddPathList(Security.Permissions.FileIOPermissionAccess.AllAccess, My.Application.Info.DirectoryPath & "Sites_int.wblist")<br/>
Permission.Demand()
But I still get the "...cannot access..." error
How can I fix this?
View the full article
being used by another process", and the "source" of the exception is "mscorlib"
Note: this is a DLL file, which is being used by an application.
I tried to use:
If IO.File.Exists(My.Application.Info.DirectoryPath & "Sites_int.wblist") = True Then<br/>
Kill(My.Application.Info.DirectoryPath & "Sites_int.wblist")<br/>
End If<br/>
IO.File.WriteAllText(My.Application.Info.DirectoryPath & "Sites.wblist", FullString)<br/>
Catch ex As Exception<br/>
MsgBox("An error has occoured:" & vbNewLine & ex.Message & vbNewLine & ex.Source, MsgBoxStyle.Critical, "Error")<br/>
End Try
And when I try to read it:
SList = IO.File.ReadAllLines(My.Application.Info.DirectoryPath & "Sites_int.wblist").ToList
I tried to set permissions:
Dim Permission As New System.Security.Permissions.FileIOPermission(Security.Permissions.PermissionState.Unrestricted, My.Application.Info.DirectoryPath & "MyDLL.dll")<br/>
Permission.AddPathList(Security.Permissions.FileIOPermissionAccess.AllAccess, My.Application.Info.DirectoryPath & "Sites_int.wblist")<br/>
Permission.Demand()
But I still get the "...cannot access..." error
How can I fix this?
View the full article