WebFile Object

Microsoft FrontPage Visual Basic

WebFile Object

Multiple objects WebFile
Multiple objects

Represents a file in a Microsoft FrontPage-based Web site. The WebFile object is a member of the WebFiles collection. The WebFiles collection represents all of the files in a specified WebFolder object. Within the WebFiles collection, individual WebFile objects are indexed beginning with zero. The WebFile object is similar to a file in a directory-based hierarchy. FrontPage provides the ability to create multiple Web objects on a Web server. Any WebFolder can represent a Web site, but every WebFolder does not necessarily represent a Web site.

Using the File object

Use WebFiles(index), where index is the ordinal number of a Web page, to return a single WebFile object. The following example returns the file name of the first Web page in the WebFiles collection.

ActiveWeb.RootFolder.Files(0).Name
		

Use the File object to return information about a file on a Web site. The following example returns the Name, Title, and Url properties of each File object on the active Web site.

Note  To run this program, you must have a least one Web site open.

Private Sub GetWebFileInfo()
    Dim myWeb As WebEx
    Dim myFiles As WebFiles
    Dim myFile As WebFile
    Dim myFileName As String
    Dim myTitle As String
    Dim myUrl As String

    Set myWeb = ActiveWeb
    Set myFiles = myWeb.RootFolder.Files

    With myWeb
        For Each myFile In myFiles
            myFileName = myFile.Name
            myTitle = myFile.Title
            myUrl = myFile.Url
        Next
    End With
End Sub
		

Use the IsOpen property to check if a file is currently open in Page view. The following example returns the IsOpen property for a specified File object. Notice that the Edit method is used to open the file in this example. For more information on using these methods, see the Edit method.

Note  You must have a Web site open to run this program.

Private Sub CheckForOpenFile()
    Dim myWeb As WebEx
    Dim myFiles As WebFiles
    Dim myFile As WebFile
    Dim myFileToOpen As String
    Dim myMessage As String
    Dim myFileName As String

    Set myWeb = ActiveWeb
    Set myFiles = myWeb.RootFolder.Files

    myFileToOpen = "index.htm"
    myMessage = "This file is currently open."

    With myWeb
        For Each myFile In myFiles
            myFileName = myFile.Name
            If myFileName = myFileToOpen Then
                If myFile.IsOpen = True Then
                    MsgBox (myMessage)
                    Exit Sub
                Else
                    myFile.Edit fpPageViewNormal
                    Exit Sub
                End If
           End If
        Next
    End With
End Sub
		

Use the Checkin, Checkout, and UndoCheckout methods to manage file resources through source control on a Web site. The following statement checks out the first file in the active Web site.

Note  You must have a source control project set up in order for this to work.

myFileCheckedOut = ActiveWeb.RootFolder.Files(1).Checkout
		

Similar to file management features in Microsoft Visual SourceSafe, FrontPage also provides an UndoCheckout method that you can use to return a file to its original state. The following statement returns the file to its original state.

myFileCheckedOut = ActiveWeb.RootFolder.Files(1).UndoCheckout
		

You can use the CheckedoutBy property before attempting to check out a file to see if the file is currently checked out and by whom. The following statement returns the logon alias of the person who checked out a file or is null if the file isn't currently checked out.

myWhoCheckedOutFile = ActiveWeb.RootFolder.Files(0).CheckedoutBy
		

Use the Properties property to return information about a Web site, such as the type of Web server (vti_webservertype) or if the Web site has a search bot (vti_hassearchbot). The Properties property returns a collection of key-value pairs used to maintain the meta information. The following statement returns True for the variable mySearchBot if the Web site has a search bot.

mySearchBot = ActiveWeb.Properties.Item("vti_hassearchbot")
		

Use the MetaTags property to return information about the meta tags contained in the HTML coding of a file. The MetaTags property returns a collection of meta tags for a File object, such as the generator of the file. The following example returns the file name and meta tags for each file in a Web site.

Note  To run this program, you must have a least one Web site open.

Private Sub GetMetaTags()
    Dim myWeb As WebEx
    Dim myMetaTag As Variant
    Dim myFiles As WebFiles
    Dim myFile As WebFile
    Dim myMetaTags As MetaTags
    Dim myFileName As String
    Dim myMetaTagName As String

    Set myWeb = ActiveWeb
    Set myFiles = myWeb.RootFolder.Files

    With myWeb
        For Each myFile In myFiles
            Set myMetaTags = myFile.MetaTags
            For Each myMetaTag In myMetaTags
                myFileName = myFile.Name
                myMetaTagName = myMetaTag
            Next
        Next
    End With
End Sub
		

Use the SharedBorders property to return the shared borders on the current Web page or to set new shared borders. The following statement returns the top shared border of the first file in the Files collection of the active Web site.

myTopBorder _
    = ActiveWeb.RootFolder.Files(0).SharedBorders(fpBorderTop)
		

You can also set shared borders on a Web page, as shown in the following statement.

ActiveWeb.RootFolder.Files(0).SharedBorders(fpBorderTop) = True
		

Use the ThemeProperties property to return information about whether the theme uses vivid colors or active graphics. The following example returns the properties of an applied theme and adds vivid colors to the current theme properties if vivid colors haven't been applied to the specified object.

Private Sub CheckThemeProperties()
    Dim myFile As WebFile

    Set myFile = ActiveWeb.RootFolder.Files(0)

    If myFile.ThemeProperties(fpThemeActiveGraphics) Then
        myFile.ApplyTheme myFile.ThemeProperties(fpThemeName), myFile.ThemeProperties(fpThemePropertiesAll) + fpThemeVividColors
    Else
        myFile.ApplyTheme myFile.ThemeProperties(fpThemeName), myFile.ThemeProperties(fpThemePropertiesAll) + fpThemeActiveGraphics + fpThemeVividColors
    End If
End Sub
		

Using File methods

Use the Copy, Delete, Edit, Move, or Open methods to manage your Web pages. There's a subtle distinction between the Edit and Open methods. With the Edit method, you can open and modify a FrontPage-compatible file into a PageWindow object. With the Open method, you can open both FrontPage-compatible files and any other type of file such as image or text files, into the file's associated editor. When you use the Open method to open a file type that is not FrontPage-compatible, FrontPage does not return a file object. The following example opens a file, deletes a file, and moves a file.

Note  To run this example, you must have a Web site called "C:\My Documents\My Webs Sites\Coho Winery".

Private Sub OpenFile()
    Dim myWeb As WebEx
    Dim myFile As WebFile

    Set myWeb = Webs.Open("C:\My Documents\My Webs Sites\Coho Winery")
    myWeb.Activate
    Set myFile = myWeb.RootFolder.Files("index.htm")
    myFile.Open
End Sub

Private Sub DeleteFile()
    Dim myWeb As WebEx
    Dim myFile As WebFile

    Set myWeb = ActiveWeb
    Set myFile = myWeb.RootFolder.Files(0)

    myFile.Delete
End Sub

Sub MoveFile()
    Dim myWeb As WebEx
    Dim myFile As WebFile

    Set myWeb = ActiveWeb
    Set myFile = myWeb.RootFolder.Files(0)

    myFile.Move "New Filename", True, True
End Sub