G
Guest
I have two questions related to FileStreams.
1. Is there any way to determine whether a file has the permissions that are
required by a FileStream constructor? For example, given the following
sample:
Dim fs1 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.ReadWrite, IO.FileShare.Read)
'...
'This is allowed.
Dim fs2 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.Read, IO.FileShare.ReadWrite)
'...
'This raises a System.IO.IOException exception.
Dim fs3 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.ReadWrite, IO.FileShare.Read)
Is there any way to test C:\Test.txt for the required permission before fs3
is instantiated (and thus raises an exception)? Note that in general, my app
would not have knowledge of fs1 or fs2 when fs3 is instantiated.
2. Once a FileStream has been created, is there any way to rename the
corresponding file without closing the FileStream? For example, I would like
to do this:
Dim fs As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.ReadWrite, IO.FileShare.Read)
'...
System.IO.File.Move("C:\Test.txt", "C:\Test2.txt")
In this case my app would have knowledge of fs if that helps.
Thanks for any help.
Lance
1. Is there any way to determine whether a file has the permissions that are
required by a FileStream constructor? For example, given the following
sample:
Dim fs1 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.ReadWrite, IO.FileShare.Read)
'...
'This is allowed.
Dim fs2 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.Read, IO.FileShare.ReadWrite)
'...
'This raises a System.IO.IOException exception.
Dim fs3 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.ReadWrite, IO.FileShare.Read)
Is there any way to test C:\Test.txt for the required permission before fs3
is instantiated (and thus raises an exception)? Note that in general, my app
would not have knowledge of fs1 or fs2 when fs3 is instantiated.
2. Once a FileStream has been created, is there any way to rename the
corresponding file without closing the FileStream? For example, I would like
to do this:
Dim fs As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.ReadWrite, IO.FileShare.Read)
'...
System.IO.File.Move("C:\Test.txt", "C:\Test2.txt")
In this case my app would have knowledge of fs if that helps.
Thanks for any help.
Lance