Share via


WebFolders Collection

SharePoint Designer Developer Reference

A collection of WebFolder objects. Each WebFolder object within the WebFolders collection represents a folder in a Web site. The WebFolder object is a member of the WebFolders collection.

Remarks

All of the methods that involve changing the location of a folder, such as Copy or Move, change the location only within the current Web site; you cannot move a folder from one Web site to a another Web site.

Use WebFolders(Index), where Index is the index number of an item in the WebFolders collection, to return a single WebFolder object. The following example returns the first WebFolder object in the collection.

Visual Basic for Applications
Set myFolder = ActiveWeb.RootFolder.Folders(0)

Use the Add method to add a new WebFolder object to the WebFolders collection in a Web site. Both of the following statements add a WebFolder object to the collection of WebFolders in the active Web site. Parentheses are not required for the folder name, as shown in the second statement.

Note

The FolderUrl argument within the quotation marks ("Coho Winery") should include only the new folder name, not the entire URL, unless you are adding a new URL to the location designated as the FolderUrl. The program fails if the entire URL is included for existing URLs.

Visual Basic for Applications
ActiveWeb.RootFolder.Folders.Add ("Coho Winery")
ActiveWeb.RootFolder.Folders.Add "Coho Winery"

Use the Count property to return the number of navigation nodes in the WebFolders collection. The following statement returns the number of Web folders in the Coho Winery Web site.

Visual Basic for Applications
Webs("C:\Web Server One\Coho Winery").Folders.Count

Use the Delete method to delete a folder from a Web site. The first statement deletes the tenth WebFolder object. The second statement uses the name of the folder instead of the index number to designate the folder to delete.

Visual Basic for Applications
ActiveWeb.RootFolder.Folders(9).Delete
ActiveWeb.RootFolder.Folders("TempFolder").Delete

Use the Copy method to copy a WebFolder object. The following example copies a folder (WebFolders(4)) to another folder on the active Web site (Chardonnay Inventory). For purposes of this example, WebFolders(4) is a folder named Inventory in the Coho Winery Web site. This folder contains the entire wine inventory—but the Web designer wanted to feature the sale on Chardonnay wines and created a temporary folder that will be edited to contain only Chardonnay wine.

Visual Basic for Applications
Private Sub CopyInventory()
    Dim myFolder As WebFolder
    Set myFolder = ActiveWeb.RootFolder.Folders(4)
    myFolder.Copy ("C:\Coho Winery\Chardonnay Inventory, False, True)
End Sub

Use the Parent property when you want to return the container for the WebFolders collection. The following statement returns the container for the fourth folder.

Visual Basic for Applications
myParent = Webs.RootFolder.Folders(3).Parent

See Also