Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Managing Publishing with MetaTags

Managing Publishing with MetaTags

Automate publication of your Web site by using a combination of events such as OnBeforeWebPublish and metadata that can be obtained by accessing the data in the Properties collection. For example, before publishing a Web site, you might want to check the metadata for all of the pages in the Web site. To determine whether Microsoft Office SharePoint Designer generated all of the pages in your Web site, use the following code in the OnBeforeWebPublish 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 Office SharePoint Designer."
        End If
        'Check all web pages.
        For Each myMetaTag In myMetaTags
            If myMetaTag = "generator" Then
              If myFile.Properties("vti_generator") = _
                "Microsoft Office SharePoint Designer 4.0" Then
                Exit For
              Else
                MsgBox myFile.Name & " was not generated by Office SharePoint Designer."
              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 is not to be published, the vti_donotpublish property key is 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

You can use the vti_donotpublish property key to disable publishing. When publishing is complete, the file is 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


Community Additions

ADD
Show:
© 2015 Microsoft