Метод SPWebCollection.Add (String, String, String, UInt32, SPWebTemplate, Boolean, Boolean)
Создает объект SPWeb с указанного сайта URL-адрес, заголовок, описание, идентификатор языкового стандарта и определения сайта или объекта шаблона сайта.
Пространство имен: Microsoft.SharePoint
Сборка: Microsoft.SharePoint (в Microsoft.SharePoint.dll)
Синтаксис
'Декларация
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
Тип: System.StringСтрока, содержащая новый URL-адрес веб-сайта относительно корневого веб-сайта в семействе сайтов. Например для создания веб-сайта в http://MyServer/sites/MySiteCollection/MyNewWebsite, укажите MyNewWebsiteили создать один уровень веб-сайт снижение на http://MyServer/sites/MySiteCollection/Website/MyNewWebsite, укажите Website/MyNewWebsite.
strTitle
Тип: System.StringСтрока, содержащая название.
strDescription
Тип: System.StringСтрока, содержащая описание.
nLCID
Тип: System.UInt3232-разрядная версия целое число без знака, задающее код языка.
WebTemplate
Тип: Microsoft.SharePoint.SPWebTemplateОбъект SPWebTemplate , который представляет определение веб-сайта или шаблона сайта.
useUniquePermissions
Тип: System.Booleantrue для создания дочернего сайта, который не наследует разрешения от другого сайта; в противном случае — false.
bConvertIfThere
Тип: System.Booleantrue преобразовать существующую папку с таким же именем на сайте SharePoint. false исключение, которое указывает, что URL-адрес с именем указанного сайта уже существует.
Возвращаемое значение
Тип: Microsoft.SharePoint.SPWeb
Объект SPWeb , который представляет веб-сайта.
Замечания
По умолчанию шаблон узла global (GLOBAL#0) добавляется всех определений сайтов. Не удается явно создать сайт на основе шаблона глобальный сайт.
Примеры
Следующий пример является частью более крупного проекта, где используется компонент веб сайтов для создания дочернего сайта под веб-сайт, где активирован компонент. Компонент включает обработчик событий, который реализует класс 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