Managing Publishing with MetaTags

See Also

Automate publishing your web by using a combination of events such as OnBeforeWebPublishing and meta data that can be obtained from accessing the data in the Properties collection. For example, before publishing a web, you might want to check the meta data for all of the pages in the web. To check if Microsoft FrontPage generated all of the pages in your web, use the following code in the OnBeforeWebPublishing event, along with an event handler.

Private Sub CheckIfFP()
Dim myFiles As WebFiles
Dim myFile As WebFile
Dim myMetaTags As MetaTags
Dim myMetaTag As Variant

Set myFiles = ActiveWeb.RootFolder.Files

For Each myFile In myFiles
    Set myMetaTags = myFile.MetaTags
    'Check for any text files.
    If myMetaTags.Count = 0 And _
        myFile.Extension <> ".asa" Then
        MsgBox myFile.Name & " was not generated by FrontPage."
    End If
    'Check all web pages.
    For Each myMetaTag In myMetaTags
        If myMetaTag = "generator" Then
          If myFile.Properties("vti_generator") = _
            "Microsoft FrontPage 4.0" Then
            Exit For
          Else
            MsgBox myFile.Name & " was not generated by FrontPage."
          End If
        End If
    Next
Next
End Sub

You can also check the value of the vti_donotpublish property key before publishing. If the document is a draft or a document that isn't to be published, the vti_donotpublish property key will be set to True. The following example checks the value of the vti_donotpublish property key.

Dim myFiles As WebFiles
Dim myFile As WebFile

For Each myFile In myFiles
    If myFile.Properties("vti_donotpublish") = True Then
        MsgBox "Do not publish " & myFile.Name
    End If
Next

The vti_donotpublish property key can be used to disable publishing. When publishing is complete, the file will not be published to the server. The following example disables publishing for the first file in the Files collection.

Sub PublishThisFile(myFileName As String, myStatus As Boolean)
Dim myFile As WebFile

Set myFile = ActiveWeb.LocateFile(myFileName)

Call myFile.Properties.Add("vti_donotpublish", Not (myStatus))
myFile.Properties.ApplyChanges
End Sub

Private Sub PublishFile()
PublishThisFile Activeweb.RootFolder.Files(0), False
End Sub