Private Sub test2(MyDwg As String)
If IsFileLocked(New IO.FileInfo(MyDwg)) = False Then
Using db As New Database(False, True)
db.ReadDwgFile(MyDwg, IO.FileShare.ReadWrite, False, "")
Dim workDb As Database = HostApplicationServices.WorkingDatabase
If HostApplicationServices.WorkingDatabase <> db Then
HostApplicationServices.WorkingDatabase = db
End If
Using MyTrans As Transaction = db.TransactionManager.StartTransaction()
Try
If db.Orthomode = True Then
db.Orthomode = False
Else
db.Orthomode = True
End If
db.Saveproxygraphics = 0
MyTrans.Commit()
db.SaveAs(MyDwg, DwgVersion.Current)
Catch
MyTrans.Abort()
db.CloseInput(True)
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbCrLf + "Could Not Save Drawing " & MyDwg)
Finally
If HostApplicationServices.WorkingDatabase <> workDb Then
HostApplicationServices.WorkingDatabase = workDb
End If
End Try
End Using
db.Dispose()
End Using
Else
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbCrLf + "Could Not Open Drawing " & MyDwg)
End If
End Sub
Private Function IsFileLocked(ByVal file As IO.FileInfo) As Boolean
Dim stream As IO.FileStream = Nothing
Try
stream = file.Open(IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None)
Catch
Return True
End Try
If (Not (stream) Is Nothing) Then
End If
Return False
End Function