共用方式為


SPFolderCollection.Add Method

Adds the folder that is located at the specified URL to the collection.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableExceptionConstraintAttribute(FixedId := "2", Condition := "Lack of permissions to perform the operation.",  _
    ErrorType := GetType(UnauthorizedAccessException))> _
<ClientCallableMethodAttribute(ReturnObjectIdentity := True, AddReturnValueToCollection := True)> _
<ClientCallableExceptionConstraintAttribute(FixedId := "1", Condition := "Value does not fall within the expected range.",  _
    ErrorType := GetType(ArgumentException))> _
Public Function Add ( _
    strUrl As String _
) As SPFolder
'Usage
Dim instance As SPFolderCollection
Dim strUrl As String
Dim returnValue As SPFolder

returnValue = instance.Add(strUrl)
[ClientCallableExceptionConstraintAttribute(FixedId = "2", Condition = "Lack of permissions to perform the operation.", 
    ErrorType = typeof(UnauthorizedAccessException))]
[ClientCallableMethodAttribute(ReturnObjectIdentity = true, AddReturnValueToCollection = true)]
[ClientCallableExceptionConstraintAttribute(FixedId = "1", Condition = "Value does not fall within the expected range.", 
    ErrorType = typeof(ArgumentException))]
public SPFolder Add(
    string strUrl
)

Parameters

  • strUrl
    Type: System.String

    A string that specifies the URL of the folder.

Return Value

Type: Microsoft.SharePoint.SPFolder
An SPFolder object that represents the folder.

Examples

The following code example adds a folder to the specified Web site.

Dim site As SPSite = SPControl.GetContextSite(Context)
Dim folders As SPFolderCollection = site.AllWebs("Site_Name").Folders

folders.Add("Folder_Name") 
SPSite oSiteCollection = SPContext.Current.Site;
SPFolderCollection collFolders = 
    oSiteCollection.AllWebs["Site_Name"].Folders;
collFolders.Add("Folder_Name");

See Also

Reference

SPFolderCollection Class

SPFolderCollection Members

Microsoft.SharePoint Namespace