title: Revit API, Prevent document opening
body: <p>I would like to prevent users from opening a sepcific template (rte) file directly.
  My thoughts are to check the file name that is opening if it is the specific template then close it after a dialog notifying the user to user proper procedures creating a project from said template.
  I'm working in VB.net (visual basic not c) &amp; Revit 2019 &amp; 2022
  Not sure if it's best to embed the code in the document or application.
  I've played around with some code in the document but can't get the file to close.</p>
  <p>Any ideas/feedback would be helpful.</p>
  <pre><code>Imports System
  Imports System.IO
  Imports Microsoft.VisualBasic
  Imports Autodesk.Revit.UI
  Imports Autodesk.Revit.DB
  Imports Autodesk.Revit.UI.Selection
  Imports System.Collections.Generic
  Imports System.Linq
  
  &lt;Autodesk.Revit.Attributes.Transaction(Autodesk.Re vit.Attributes.TransactionMode.Manual)&gt; _
  &lt;Autodesk.Revit.DB.Macros.AddInId(&quot;87A056AA-AEB8-4E72-8DCC-D03CA2C8141B&quot;)&gt; _
  Partial Public Class ThisDocument
  Private Sub Module_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
  Dim curDoc As Document = Me.Application.ActiveUIDocument.Document
  Dim DocName As String = curDoc.PathName
  Dim CurAdmin As String = Environment.UserName
  Dim RevComID As RevitCommandId = RevitCommandId.LookupCommandId(&quot;ID_FILE_CLOSE&quot;)
  Dim uiDoc As UIDocument = Me.Application.ActiveUIDocument
  If DocName = &quot;NetworkTemplatePath\_Templates\Revit 2019.rte&quot; Then
  TaskDialog.Show(&quot;ACCESS ALERT&quot;, &quot;DO NOT OPEN THIS TEMPLATE DIRECTLY&quot; &amp; vbCrLf &amp; &quot;Create a Temporary project from the template to access family content&quot; &amp; vbCrLf &amp; _
  vbCrLf &amp; &quot;Contact the BIM Manager if you require further assistance&quot; &amp; vbCrLf &amp; vbCrLf &amp; &quot;This template file will now be closed&quot;)
  End If
  ‘This is temporary..
  ‘Future code will be to close the template for designers only, allowing BIM Manager/Coordinator access to editing the template.
  Dim CloseDoc As Boolean
  CloseDoc = MsgBox(&quot;Close Template&quot;, vbYesNo)
  If CloseDoc Then
  uiDoc.SaveAndClose ‘&lt;--- THIS IS NOT WORKING
  End If
  End Sub
  Private Sub Module_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
  End Sub
  End Class
  </code></pre>