用 MetaTags 管理发布

   

使用事件(例如 OnBeforeWebPublish)和 meta 数据(可以通过访问 Properties 集合中的数据获得)的组合可以自动发布站点。例如,在发布站点之前,您可能要检查站点中所有网页的 meta 数据。若要检查 Microsoft FrontPage 是否生成了站点中的所有网页,请使用下列 OnBeforeWebPublishing 事件中的代码以及事件处理器。

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

发布前,您也可检查 vti_donotpublish 属性关键字的值。若文档仍在草稿阶段或者尚未准备发布,vti_donotpublish 属性关键字会设为 True。下列示例检查 vti_donotpublish 属性关键字的值。

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

vti_donotpublish 属性关键字可用来禁止发布。当发布完成时,文件将不会发布到服务器。下列示例禁止 Files 集合中第一个文件的发布。

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