创建 Web 站点

   

本主题中的部分内容可能不适用于某些语言。

使用 Microsoft FrontPage 创建基于 FrontPage 的站点就像在硬盘上创建新文件夹一样简单。FrontPage 成功管理站点的关键在于规划站点的结构与设计。大多数的 Web 服务器只能有一个站点,而使用 FrontPage,您可以根据需要创建任意多的站点(包括嵌套站点)。基于 FrontPage 的站点包含三个层次,分别为:站点结构、文件夹结构和导航结构。单击下面的链接可选择指定的主题。

了解 FrontPage 的站点结构

了解 FrontPage 的文件夹结构

了解导航结构

利用程序创建 Web 站点

使用 Add 方法创建 Web 站点

使用 MakeWeb 方法创建 Web 站点

了解 FrontPage 的站点结构

您的 web 服务器上的任何文件夹都可以是一个有自己的文件夹分层结构的站点,分层结构里可包含原始站点之下的子站点。安装 FrontPage 时,安装程序将自动为您的主站点提供默认名。在基于磁盘的系统上,默认名为 C:\My Documents\My Webs(Microsoft Windows 操作系统上)或 C:\WINNT\Profiles\logon alias\Personal\My Webs (Microsoft Windows NT 操作系统上)。您可能想把各子站点命名为各公司的名字,例如 Adventure Works、American Society of Science、Mightyflight Toys 或 Rogue Cellars 等。

FrontPage 提供了各种站点模板(公司、讨论、客户支持等),这些模板提供了创建各种站点的基础结构。例如,Adventure Works 公司要求您创建一个成熟完整的公司展现网站,等等。基于磁盘的站点结构图如下。

以下图形显示了“文件夹”视图中的站点结构。该文件夹图标中的子站点显示为小地球仪。

了解 FrontPage 的文件夹结构

FrontPage 文件夹结构的行为模式与 Windows 资源管理器中的文件夹结构相同,不过,要从 Windows 资源管理器中访问这些文件,就必须把它们导出到其他位置,如硬盘或服务器。在导出的过程中,文件会被转换为 HTML 网页。从这个意义上说,打开 FrontPage 就像打开站点的一扇窗户。基于磁盘的站点的文件夹结构图如下。

以下图表显示了“文件夹”视图中的文件夹结构。

注意  本图与前一幅图显示的信息相同,这是因为是在同一视图下显示文件夹与站点,但您可从站点与文件夹图表中看出它们具有不同的结构。站点或子站点是文件夹。不过,一个同样是站点的文件夹包含了有关该站点的 meta 数据。例如,若向您的某个站点应用主题,则所有位于该站点中的文件夹都将拥有相同的主题。不过,您可以为您的 web 服务器上的各站点应用不同的主题。当您将站点更改为文件夹,同时也就删除了使该文件夹成为站点的特殊设置,以及诸如主题更改(使其匹配为您的基于 FrontPage 的子站点提供容器的基于磁盘的或基于服务器的站点的“全球策略”主题)等的设置。

了解导航结构

您可以在自己的站点中创建文件,但创建文件时,并不会自动创建将这些文件链接到站点的导航结构。不过,各子站点可以有自己的主页。主页通常是导航结构中所有站点的初始网页;不过在 FrontPage 中您可以为主页创建位于同一导航层次上的替换网页。您可在主页上添加链接,让这些链接导航至您要维护的其他子站点的主页。

导航结构包含链接您子站点中各网页的站点,并提供指向导航结构中各网页的指针。以下图表显示基于磁盘的导航结构。

以下图表显示“导航”视图中的导航结构。

利用程序创建 Web 站点

这里有一个很简单的站点设计,Rogue Cellars 公司要添加一个名为“Wines Around the World”的子站点,起始网页包含两个国家 — 西班牙和法国。文件夹结构将包含 Rogue Cellars 站点和子站点 (Wines Around the World) 的文件夹,以及隐藏文件夹 _private 和一个 Image 文件夹。导航结构将包含 Wines Around the World 的主页 (index.htm) 和两个子网页 (Spain.htm 和 France.htm,浏览结构中的左节点和右节点)。

在 Microsoft Visual Basic for Applications 中,有两个方法可创建基于 FrontPage 的站点。您可以使用 Webs 集合的 Add 方法,或者使用 WebFolder 对象的 MakeWeb 方法将现有文件夹更改为站点。

使用 Add 方法创建 Web 站点

一旦您设计好 Web 站点的外观和工作方式,您可以使用下列过程所示的 Set 语句来创建新站点。

注意   若要运行本主题中的示例,您需要有一站点,其名称为 “C:\My Documents\ My Webs\Rogue Cellars”(对于 运行在 Microsoft Windows 上的服务器)或 ”C:\WINNT\Profiles\logon alias\Personal\My Webs\Rogue Cellars”(Windows NT 的服务器上)。或者,您可以用您自行选择的站点或文件来代替。

Private Sub Add()
    Dim myNewWeb As WebEx

    Set myNewWeb = _
        Webs.Add("C:\My Webs\Rogue Cellars\Wines Around the World")
End Sub

用此方法创建站点时,您只是创建了站点及其文件夹,而没有创建具备所有文件夹、网页和导航结构的完整 Web 站点。下一个步骤是添加主页。下面加粗显示的语句用于添加主页,同时将该语句添加到上一个程序中。

Private Sub Add()
    Dim myNewWeb As WebEx
    Dim myFiles As WebFiles Dim myUrl As String

    Set myNewWeb = _
        Webs.Add("C:\My Webs\Rogue Cellars\Wines Around the World")
    Set myFiles = myNewWeb.RootFolder.Files myFileUrl = _         "C:\My Webs\Rogue Cellars\Wines Around the World\index.htm" myFiles.Add(myFileUrl)
End Sub

因为 index.htm 或 default.htm 常常被用来当作主页的文件名称,当您使用这两个文件名时,FrontPage 就会创建适当的主页导航结构。但如果您用 WebFile 对象的 Add 方法进一步创建网页,您可以加入网页,但 FrontPage 不会自动创建导航结构,您必须要以手动的方式加入浏览结构,如下面加粗的语句所示。

注意  以下示例在 Rogue Cellars 站点中创建新站点,并且在新站点中创建两个网页,分别是 index.htm 和 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 Webs\Rogue Cellars\Wines Around the World")
    Set myFiles = myNewWeb.RootFolder.Files
    myFileUrl = _
        "C:\My Webs\Rogue Cellars\Wines Around the World\index.htm"

    myFiles.Add(myFileUrl)
    myFileOne = "C:\My Webs\Rogue Cellars\Wines Around the World\" myFileOne = myFileOne & "Spain.htm" myFiles.Add myFileOne Call myNewWeb.HomeNavigationNode.Children.Add(myFileOne, "Spain", _         fpStructLeftmostChild) myNewWeb.ApplyNavigationStructure

End Sub

注意最后加粗的语句,此方法将所做的更改应用于导航结构中。

有一些常数可以应用于 Children 属性的 Add 方法中:fpStructBaseOnSiblingfpStructLeftmostChildfpStructRightmostChild。非常简单,这些常数告知 FrontPage 您要将文件放置于导航结构中的左边、右边还是根据其他同级对象的位置放置。此处,myFileOne 成为主页最左边的子网页。下一个步骤是添加下一页,这样您就可以在“导航”视图中查看导航结构。下述加粗语句将在先前的站点中添加另一个网页和导航节点。

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 Webs\Rogue Cellars\Wines Around the World")
    Set myFiles = myNewWeb.RootFolder.Files
    myFileUrl = _
        "C:\My Webs\Rogue Cellars\Wines Around the World\index.htm"

    myFiles.Add(myFileUrl)
    myFileOne = "C:\My Webs\Rogue Cellars\Wines Around the World\"
    myFileOne = myFileOne & "Spain.htm"
    myFileTwo = "C:\My Webs\Rogue Cellars\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

您可以用这种方式继续在站点中添加网页和导航站点,直至完成您的站点。或者,您可以创建 For 循环,根据需要的数目重复加入您需要的网页和导航站点以完成站点。以下示例加入五个网页和导航站点到 Rogue Celars 站点中的新站点。

注意  修改导航结构的同时创建、移动或删除文件和文件夹可能会导致某些更改丢失。首先请更改站点的文件夹结构,再更改导航结构,然后将导航结构应用于站点。

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 Webs/Rogue Cellars/")
    myParentWeb.Activate

    myBaseURL = "C:/My Documents/My Webs/Rogue Cellars/"
    myWebURL = myBaseURL & "Rogue Cellars 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

使用 MakeWeb 方法创建 Web 站点

若您已经有了文件夹,而想将其转换成站点,则可以使用 WebFolder 对象的 MakeWeb 方法,如以下过程所示。

注意   本过程假设 Webs(0) 是 Rogue Cellars 站点而且其中包含一个名为 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

若 PageOne 是 Rogue Cellars 的子站点,则您需创建一个导航结构。