Creating Web Sites
Some of the content in this topic may not be applicable to some languages.
Microsoft FrontPage makes FrontPage-based Web site creation as easy as creating a new folder on your hard drive. The key to successful Web site management in FrontPage is planning the structure and design of your Web sites. With most Web servers, you have one Web site, but with FrontPage, you can create as many Web sites as you want, including nested Web sites, called subsites. A FrontPage-based Web site comprises three layers
Understanding FrontPage Web structure
Understanding FrontPage folder structure
Understanding navigation structure
Creating Web sites programatically
Creating a Web site with the Add method
Creating a Web site with the MakeWeb method
Understanding FrontPage Web structure
Any folder on your Web server can be a Web site with its own folder hierarchy that can include subsites below the original Web site. When you install FrontPage, the program automatically provides a default name for your main Web site. On a disk-based system, the default name is C:\Documents and Settings\user name\My Documents\My Web Sites for Microsoft Windows XP. You may want to name the individual subsites for the various company names themselves, such as Adventure Works, American Society of Science, Mightyflight Toys, or Coho Winery.
FrontPage provides a variety of Web site templates
The following figure shows the Web site structure in Folders view. The subsites display a small globe within the folder icon.
Understanding FrontPage folder structure
The folder structure in FrontPage behaves in the same manner as the folder structure in Windows Explorer. However, to access these files from Windows Explorer, you have to export them to another location
The following diagram shows the folder structure in Folders view.
Note This diagram displays the same information as the previous one because both folders and Web sites are displayed in the same view, but you can see from the Web site and folder diagrams that they each have their own structure. A Web site or subsite is a folder. However, a folder that is also a Web site contains meta data about that Web site. For example, if you apply a theme to one of your Web sites, all folders within that Web site will have the same theme. However, you can apply different themes to the Web sites on your Web server. When you change a Web site to a folder, you remove special settings that make that folder a Web site, and settings such as the theme change to match the "global" theme for the disk-based or server-based Web site that provides the container for your FrontPage-based subsites.
Understanding navigation structure
You can create files within your Web site, but the navigation structure that links these files to your Web site isn't automatically created when the files are created. However, each subsite can have its own home page. A home page is usually the starting page for any Web site in the navigation structure; but in FrontPage you can create alternate pages that exist at the same navigation level as the home page. You may want to add links to a home page that navigate to the home pages of other subsites that you're maintaining.
The navigation structure contains nodes that link each of the pages in your subsites and provide pointers to the locations of each page in the navigation structure. The navigation structure for a disk-based Web site is shown in the following diagram.
The following diagram shows the navigation structure in Navigation view.
Creating Web sites programmatically
Here's a very simple design for a Web site. The Coho Winery company wants to add a subsite called Wines Around the World that will start with pages for two regions, Spain and France. The folder structure will contain the Coho Winery Web site and the folder for the subsite, Wines Around the World, plus the hidden folder _private, and an Images folder. The navigation structure will contain the Wines Around the World home page (index.htm) and the two child pages (Spain.htm and France.htm
There are two ways to create FrontPage-based Web sites in Microsoft Visual Basic for Applications. You can use the Add method with the Webs collection, or you can use the MakeWeb method with a WebFolder object to change an existing folder into a Web site.
Creating a Web site with the Add method
Once you've designed how your Web site is going to look and function, you can use the Set statement as shown in the procedure below to create a new Web site.
Note To run the examples in this topic, you must have a Web site called "C:\My Documents\My Web Sites\Coho Winery", or you may substitute a Web site and files of your choice.
Private Sub Add()
Dim myNewWeb As WebEx
Set myNewWeb = _
Webs.Add("C:\My Web Sites\Coho Winery\Wines Around the World")
End Sub
When you create a Web site with this method, you only create the Web site and its folder; you don't create a complete Web site with all of the folders, pages, and navigation in place. The next step is adding a home page. The following example adds a home page.
Private Sub Add()
Dim myNewWeb As WebEx
Dim myFiles As WebFiles Dim myUrl As String
Set myNewWeb = _
Webs.Add("C:\My Web Sites\Coho Winery\Wines Around the World")
Set myFiles = myNewWeb.RootFolder.Files myFileUrl = _
"C:\My Web Sites\Coho Winery\Wines Around the World\index.htm"
myFiles.Add(myFileUrl)
End Sub
Because index.htm or default.htm are file names associated with names commonly used as home pages, FrontPage creates the appropriate navigation structure for a home page whenever you use one of these names. However, if you add further pages using the Add method with the WebFile object, you will add pages, but FrontPage will not automatically create the navigation structure for you
Note The following example creates a new subsite in the Coho Winery Web site and creates two pages in the new subsite: index.htm and Spain.htm.
Private Sub AddCompleteWeb()
Dim myNewWeb As WebEx
Dim myFiles As WebFiles
Dim myUrl As String
Dim myFileOne As String
Set myNewWeb = _
Webs.Add("C:\My Web Sites\Coho Winery\Wines Around the World")
Set myFiles = myNewWeb.RootFolder.Files
myFileUrl = _
"C:\My Web Sites\Coho Winery\Wines Around the World\index.htm"
myFiles.Add(myFileUrl)
myFileOne = "C:\My Web Sites\Coho Winery\Wines Around the World\"
myFileOne = myFileOne & "Spain.htm"
myFiles.Add myFileOne
Call myNewWeb.HomeNavigationNode.Children.Add(myFileOne, "Spain", _
fpStructLeftmostChild)
myNewWeb.ApplyNavigationStructure
End Sub
Notice the last statement
There are several constants you can use in the Add method for the Children
property: fpStructBaseOnSibling, fpStructLeftmostChild, and fpStructRightmostChild. Very simply, these constants inform FrontPage which position you want to apply to the file in the navigation structuremyFileOne
becomes the leftmost child of the home page. The next step is to add the next page, so that you can view the navigation structure in Navigation view. The following adds another page and navigation node to the previous Web site.
Private Sub Add()
Dim myNewWeb As WebEx
Dim myFiles As WebFiles
Dim myFileUrl As String
Dim myFileOne As String
Dim myFileTwo As String
Set myNewWeb = _
Webs.Add("C:\My Web Sites\Coho Winery\Wines Around the World")
Set myFiles = myNewWeb.RootFolder.Files
myFileUrl = _
"C:\My Web Sites\Coho Winery\Wines Around the World\index.htm"
myFiles.Add(myFileUrl)
myFileOne = "C:\My Web Sites\Coho Winery\Wines Around the World\"
myFileOne = myFileOne & "Spain.htm"
myFileTwo = "C:\My Web Sites\Coho Winery\Wines Around the World\"
myFileTwo = myFileTwo & "France.htm"
myFiles.Add myFileOne
myFiles.Add myFileTwo
Call myNewWeb.HomeNavigationNode.Children.Add(myFileOne, "Spain", _
fpStructLeftmostChild)
Call myNewWeb.HomeNavigationNode.Children.Add(myFileOne, "Spain", _
fpStructRightmostChild)
myNewWeb.ApplyNavigationStructure
End Sub
You can continue to add pages and navigation nodes to your Web site in this way until your Web site is complete. Or, you can create a For loop where you iterate through the Web site adding the number of pages and navigation nodes you need to complete the Web site. The following example adds five pages and navigation nodes to a new subsite in the Coho Winery Web site.
Note Creating, moving, or deleting files and folders while attempting to modify the navigation structure may cause some changes to be lost. First, make the changes to the folder structure of the Web site, then make the navigation structure changes, and then apply the navigation structure to the Web site.
Private Sub AddDesignerCrystalWeb()
Dim myWeb As WebEx
Dim myParentWeb As WebEx
Dim myFolders As WebFolders
Dim myFolder As WebFolder
Dim myFiles As WebFiles
Dim myNewFiles(4) As WebFiles
Dim myChildNode As NavigationNode
Dim myNewFilename As String
Dim myFileURL As String
Dim myCount As Integer
Dim myBaseURL As String
Dim myWebURL As String
Dim myInputMsg As String
Dim myExist As Boolean
Set myParentWeb = _
Webs.Open ("C:/My Documents/My Web Sites/Coho Winery/")
myParentWeb.Activate
myBaseURL = "C:/My Documents/My Web Sites/Coho Winery/"
myWebURL = myBaseURL & "Coho Winery Designer Crystal"
myExist = False
myInputMsg = _
"All files will have "".htm"" appended. Type a file name: "
Set myFolders = Webs(0).RootFolder.Folders
For Each myFolder In myFolders
'Check to see if myWebURL already exists.
If myFolder.IsWeb And myFolder.Url = myWebURL Then
myExist = True
End If
Next
'Create myWebURL if it doesn't exist.
If myExist = False Then Webs.Add(myWebURL).Activate
Set myWeb = ActiveWeb
Set myFiles = myWeb.RootFolder.Files
'Create files.
For myCount = 0 To UBound(myNewFiles)
myNewFilename = InputBox(myInputMsg)
myFileURL = myWeb.Url & "/" & myNewFilename & ".htm"
myFiles.Add myFileURL
myFiles(myFileURL).Edit
Next
'Add to navigation structure.
For myCount = 0 To UBound(myNewFiles)
'Check if the current page is index.htm, if so, skip it.
If myFiles(myCount).Title = "index.htm" Then
myCount = myCount + 1
End If
Set myChildNode = _
myWeb.RootNavigationNode.Children(0)
'Add navigation node to the current page.
myChildNode.Children.Add myFiles(myCount).Url, _
myFiles(myCount).Title, fpStructLeftmostChild
Next
myWeb.ApplyNavigationStructure
End Sub
Creating a Web site with the MakeWeb method
If you already have an existing folder that you'd like to convert to a Web site, you can use the MakeWeb method with a WebFolder object as shown in the following example.
Note The following example assumes that Webs(0)
is the Coho Winery Web site and that it contains a folder called FolderOne.
Private Sub MakeAWeb()
Dim myWeb As WebEx
Dim myFolder As WebFolder
Set myWeb = Webs(0)
myWeb.Activate
Set myFolder = ActiveWeb.RootFolder.Folders("FolderOne")
myFolder.MakeWeb
End Sub
You will need to create a navigation structure once PageOne is a subsite of Coho Winery.