Mega Code Archive
FileInfo Open with settings for File Read Write Mode, File Access Mode, File Share Mode
Imports System
Imports System.IO
Public Class OpenTest
Public Shared Sub Main()
Dim fi As New FileInfo("temp.txt")
Dim fs As FileStream = fi.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
Dim nextfi As New FileInfo("temp.txt")
Try
nextfi.Open(FileMode.OpenOrCreate, FileAccess.Read)
Console.WriteLine("The file was not locked, and was opened by a second process.")
Catch i as IOException
Console.WriteLine(i.ToString())
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
fs.Close()
End Sub
End Class