Hello,
I have a locking issue, with a file that i need to lock
My app has a ops log which needs to be user accessible, if the user has the file open i cannot write to it and the app crashes. Folderitem.writeable seems to cover only permissions, not being able to write it without crashing.
What is the best way to check(adding and removing a 1 with a binarystream?) if i can write to the file(without running into io crashes)?
Thanks!
This is the shared method used to write the strings, using a parameter called filestring(string).
[code]Dim fileStream As TextOutputStream
Dim FieldsString As String
Dim FileName As String
Dim FileTime as New Date
Dim CSVf as New Folderitem
Dim FileRow as String = 0
if filerow = 0 then
'Initialize the file
fileStream = TextOutputStream.Create(CSVf)
fileStream.WriteLine(FieldsString)
else
'Append data to file
fileStream = TextOutputStream.Append(CSVf)
end if
fileStream.WriteLine(filestring)
filerow = filerow + 1
fileStream.Close
So youâre already catching the exception. Is it actually crashing? You are effectively checking if itâs writable and displaying a file locked message. What more do you want?
Try to use the new framework
Iâve a log function like this and append with the new framework doesnât raise the exception (in most cases, OS donât work always in a predictable way)
use a try/catch is more readable and usable (personal opinion)
Never handled exceptions before
I Just dumped a codeblock lifted from a quick Google search, so I didnât know if it was the correct way. If it is, yay less time to waste on this thing