SPWebCollection.Add method (String, String, String, UInt32, SPWebTemplate, Boolean, Boolean)
使用指定的網站與相對 URL、 標題、 描述、 地區設定識別碼和網站定義或網站範本物件建立SPWeb物件。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Function Add ( _
strWebUrl As String, _
strTitle As String, _
strDescription As String, _
nLCID As UInteger, _
WebTemplate As SPWebTemplate, _
useUniquePermissions As Boolean, _
bConvertIfThere As Boolean _
) As SPWeb
'用途
Dim instance As SPWebCollection
Dim strWebUrl As String
Dim strTitle As String
Dim strDescription As String
Dim nLCID As UInteger
Dim WebTemplate As SPWebTemplate
Dim useUniquePermissions As Boolean
Dim bConvertIfThere As Boolean
Dim returnValue As SPWeb
returnValue = instance.Add(strWebUrl, _
strTitle, strDescription, nLCID, _
WebTemplate, useUniquePermissions, _
bConvertIfThere)
public SPWeb Add(
string strWebUrl,
string strTitle,
string strDescription,
uint nLCID,
SPWebTemplate WebTemplate,
bool useUniquePermissions,
bool bConvertIfThere
)
參數
strWebUrl
Type: System.String內含相對於根網站的網站集合中新的網站 URL 的字串。例如,若要在http://MyServer/sites/MySiteCollection/MyNewWebsite」 建立網站,請指定MyNewWebsite,或http://MyServer/sites/MySiteCollection/Website/MyNewWebsite在建立網站一個層級較低,指定Website/MyNewWebsite。
strTitle
Type: System.String內含標題的字串。
strDescription
Type: System.String包含描述字串。
nLCID
Type: System.UInt32帶正負號的 32 位元整數,指定地區設定識別碼。
WebTemplate
Type: Microsoft.SharePoint.SPWebTemplateSPWebTemplate物件代表的網站定義或網站範本。
useUniquePermissions
Type: System.Boolean若要建立子網站不是權限繼承自其他網站 ; true 否則,請 false。
bConvertIfThere
Type: System.Booleantrue 可將現有的同名資料夾轉換成 SharePoint 網站。 false 擲回例外狀況,指出與指定的網站名稱的 URL 路徑已經存在。
傳回值
Type: Microsoft.SharePoint.SPWeb
代表網站的SPWeb物件。
備註
根據預設,通用網站範本 (GLOBAL#0) 新增至所有的網站定義。您無法明確地建立的全域網站範本為基礎的網站。
Examples
下列範例會使用在網站範圍的功能來建立低於啟動功能之網站的子網站較大型專案的一部分。此功能包括實作SPFeatureReceiver類別的事件處理常式。建立子網站的程式碼是在 [功能受話者FeatureActivated方法。
建立新的網站之後, 的範例程式碼會將連結新增至其父網站的上方連結列或父代繼承連結至父網站的快速啟動]。
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
// Get the web site where the feature is activated.
SPWeb parentWeb = properties.Feature.Parent as SPWeb;
if (parentWeb == null)
return;
SPWeb childWeb = null;
string childName = "ourwiki";
// If a subsite by that name exists, open it.
string[] webs = parentWeb.Webs.Names;
if (webs != null && Array.IndexOf(webs, childName) >= 0)
{
childWeb = parentWeb.Webs[childName];
}
// Otherwise, create the subsite.
if (childWeb == null)
{
string title = "Wiki";
string desc = "A place to capture knowledge.";
uint lcid = parentWeb.Language;
string templateName = "WIKI#0";
childWeb = parentWeb.Webs.Add(childName, title, desc, lcid, templateName, false, false);
}
// Let the subsite use the parent site's top link bar.
childWeb.Navigation.UseShared = true;
// Get a collection of navigation nodes.
SPNavigationNodeCollection nodes = null;
if (parentWeb.Navigation.UseShared)
{
// Parent site does not have its own top link bar
// so use the parent's Quick Launch.
nodes = parentWeb.Navigation.QuickLaunch;
}
else
{
// Parent site has its own top link bar,
// so use it.
nodes = parentWeb.Navigation.TopNavigationBar;
}
// Check for an existing link to the subsite.
SPNavigationNode node = nodes
.Cast<SPNavigationNode>()
.FirstOrDefault(n => n.Url.Equals(childWeb.ServerRelativeUrl));
// No link, so add one.
if (node == null)
{
// Create the node.
node = new SPNavigationNode(childWeb.Title, childWeb.ServerRelativeUrl);
// Add it to the collection.
node = nodes.AddAsLast(node);
}
childWeb.Dispose();
parentWeb.Dispose();
}
Public Overrides Sub FeatureActivated(ByVal properties As SPFeatureReceiverProperties)
'Get the web site where the feature is activated.
Dim parentWeb As SPWeb = TryCast(properties.Feature.Parent, SPWeb)
If parentWeb Is Nothing Then
Return
End If
Dim childWeb As SPWeb = Nothing
Dim childName As String = "ourwiki"
' If a subsite by that name exists, open it.
Dim webs As String() = parentWeb.Webs.Names
If webs IsNot Nothing AndAlso Array.IndexOf(webs, childName) >= 0 Then
childWeb = parentWeb.Webs(childName)
End If
' Otherwise, create the subsite.
If childWeb Is Nothing Then
Dim title As String = "Wiki"
Dim desc As String = "A place to capture knowledge."
Dim lcid As UInteger = parentWeb.Language
Dim templateName As String = "WIKI#0"
childWeb = parentWeb.Webs.Add(childName, title, desc, lcid, _
templateName, False, False)
End If
' Let the subsite use the parent site's top link bar.
childWeb.Navigation.UseShared = True
' Get a collection of navigation nodes.
Dim nodes As SPNavigationNodeCollection = Nothing
If parentWeb.Navigation.UseShared Then
' Parent site does not have its own top link bar
' so use the parent's Quick Launch.
nodes = parentWeb.Navigation.QuickLaunch
Else
' Parent site has its own top link bar,
' so use it.
nodes = parentWeb.Navigation.TopNavigationBar
End If
' Check for an existing link to the subsite.
Dim node As SPNavigationNode = nodes.Cast(Of SPNavigationNode)().FirstOrDefault( _
Function(n) n.Url.Equals(childWeb.ServerRelativeUrl))
' No link, so add one.
If node Is Nothing Then
' Create the node.
node = New SPNavigationNode(childWeb.Title, childWeb.ServerRelativeUrl)
' Add it to the collection.
node = nodes.AddAsLast(node)
End If
childWeb.Dispose()
parentWeb.Dispose()
End Sub