DocumentLibrary 对象

         
DocumentLibrary
多个对象

代表当前站点中的文档集合。

使用 DocumentLibrary 对象

使用 Lists.Item(index) 可以返回单个 DocumentLibrary 对象,其中 index 是文档库的名称或其在集合中的位置(用数字表示)。下列示例显示活动站点中所有文档库的名称。如果站点不包含文档库,则向用户显示一条消息。

Sub ListAllLibraries()
'Displays the names of all document libraries
'in the collection.

    Dim lstWebList As List
    Dim strName As String
    Dim blnFound As Boolean

    'Set found flag to false
    blnFound = False
    'Check if any lists exist and is so, cycle through them
    If Not ActiveWeb.Lists Is Nothing Then
        For Each lstWebList In ActiveWeb.Lists
            If lstWebList.Type = fpListTypeDocumentLibrary Then
                'Set boolean flag to found and add name to string
                blnFound = True
                If strName = "" Then
                    strName = lstWebList.Name & vbCr
                Else
                    strName = strName & lstWebList.Name & vbCr
                End If
            End If
        Next
        If blnFound = True Then
            'Display names of all document libraries
            MsgBox "The names of all document libraries in the current web are:" _
                   & vbCr & strName
        Else
            MsgBox "There are no document libraries in the current web."
        End If
    Else
        'Otherwise display message to user
        MsgBox "The current web contains no lists."
    End If

End Sub

使用 List 对象的 Add 方法可以创建 fpListTypeDocumentLibrary 类型的新列表。下列示例创建名为 Newlibrary 的新文档库。

Sub NewLibrary()
'Adds a new list to the current web

    Dim objApp As FrontPage.Application
    Dim objLists As Lists

    Set objApp = FrontPage.Application
    Set objLists = objApp.ActiveWeb.Lists
    'Add new list
    objLists.Add Name:="NewLibrary", _
                 ListType:=fpListTypeDocumentLibrary, _
                 Description:="List of Shared files"

    'Display message to user
    MsgBox "A new library was added to the Lists collection."

End Sub