Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
Add Method
 Add Method (String)

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPWebCollection.Add Method (String) (Microsoft.SharePoint)
Creates a Web site object with the specified Web site-relative URL.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public Function Add ( _
    strWebUrl As String _
) As SPWeb
Visual Basic (Usage)
Dim instance As SPWebCollection
Dim strWebUrl As String
Dim returnValue As SPWeb

returnValue = instance.Add(strWebUrl)
C#
public SPWeb Add (
    string strWebUrl
)

Parameters

strWebUrl

A string that contains the new Web site URL relative to the root Web site in the site collection. For example, to create a Web site at http://MyServer/sites/MySiteCollection/MyNewWebsite, specify MyNewWebsite, or to create a Web site one level lower at http://MyServer/sites/MySiteCollection/Website/MyNewWebsite, specify Website/MyNewWebsite.

Return Value

An SPWeb object that represents the Web site.

The following code example creates a Web site within the current site collection.

Visual Basic
Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim subSites As SPWebCollection = siteCollection.AllWebs

Dim mySite As SPWeb = subSites.Add("MyNewWebsite")
mySite.Dispose()

C#
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;
SPWeb oWebsite = collWebsites.Add("Website/Subsite/MyNewSubsite");
oWebsite.Dispose();
NoteNote:

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker