Represents a file in a Microsoft FrontPage-based web. 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 index number of a web file item, to return a single WebFile object. The following example returns the file name of the first web file item in the WebFiles collection.
ActiveWeb.RootFolder.Files(0).Name
Use the File object to return information about a file on a web. The following example returns the Name, Title, and Url properties of each File object on the active web.
Note To run this program, you must have a least one web open.
Private Sub GetWebFileInfo()
Dim myWeb As Web
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 open to run this program.
Private Sub CheckForOpenFile()
Dim myWeb As Web
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. The following statement checks out the first file in the active web.
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, such as the type of Web server (vti_webservertype) or if the web 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 has a search bot.
mySearchBot = ActiveWeb.Properties.Item("vti_hassearchbot")
Use the MetaTags properties 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.
Note To run this program, you must have a least one web open.
Private Sub GetMetaTags()
Dim myWeb As Web
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.
myTopBorder _
= ActiveWeb.RootFolder.Files(0).SharedBorders(fpBorderTop)
You can also set shared borders on a web file, as shown in the following statement.
ActiveWeb.RootFolder.Files(0).SharedBorders(fpBorderTop) = True
Use the ThemeProperties property to return the following information about the applied theme: does the theme use 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 files. 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 called "C:\My Documents\My Webs\Rogue Cellars" (for a server running on Microsoft Windows) or "C:\WINNT\Profiles\logon alias\Personal\My Webs\Rogue Cellars" (for a server running on Windows NT).
Private Sub OpenFile()
Dim myWeb As Web
Dim myFile As WebFile
Set myWeb = Webs.Open("C:\My Documents\My Webs\Rogue Cellars")
myWeb.Activate
Set myFile = myWeb.RootFolder.Files("index.htm")
myFile.Open
End Sub
Private Sub DeleteFile()
Dim myWeb As Web
Dim myFile As WebFile
Set myWeb = ActiveWeb
Set myFile = myWeb.RootFolder.Files(0)
myFile.Delete
End Sub
Sub MoveFile()
Dim myWeb As Web
Dim myFile As WebFile
Set myWeb = ActiveWeb
Set myFile = myWeb.RootFolder.Files(0)
myFile.Move “New Filename”, True, True
End Sub