В предыдущем примере мы узнали, как найти узлы и коллекции узлов в браузере объектной модели SharePoint. Здесь же мы узнаем, как можно пополнить коллекцию еще одним веб-узлом.
Первое что нужно сделать – найти и пометить флагом свойство
AllWebs
одной из коллекций веб-узлов (о том, как это сделать рассказано в предыдущем примере) и создать новое окно сценария.Программа автоматически сгенерирует код сценария:
C# using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using MAPILab.SharePoint.Explorer.CodeForm; using MAPILab.SharePoint.Explorer.Utilities.ScriptRunner; public class Tester { static void Main( Microsoft.SharePoint.SPWebCollection allWebs1 ,MAPILab.SharePoint.Explorer.CodeForm.MLCodeForm thisForm ,MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.MLBrowser browser ) { // Output browser configuration //browser.Text = "Browser window"; //browser.DisplayMode = MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.DisplayMode.Expanded; browser.ReturnValue = null; } }
Visual Basic Imports System Imports System.Collections.Generic Imports System.Diagnostics Imports System.Text Imports MAPILab.SharePoint.Explorer.CodeForm Imports MAPILab.SharePoint.Explorer.Utilities.ScriptRunner Public Class Tester Shared Sub Main(ByVal allWebs1 As Microsoft.SharePoint.SPWebCollection, ByVal thisForm As MAPILab.SharePoint.Explorer.CodeForm.MLCodeForm, ByVal browser As MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.MLBrowser) ' Output browser configuration 'browser.Text = "Browser window" 'browser.DisplayMode = MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.DisplayMode.Expanded browser.ReturnValue = Nothing End Sub End Class
Все, что теперь нужно сделать – вызвать всего одну функцию SPWebCollection.Add и вернуть результат выполнения дл дальнейшего изучения:
C# using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using MAPILab.SharePoint.Explorer.CodeForm; using MAPILab.SharePoint.Explorer.Utilities.ScriptRunner; public class Tester { static void Main( Microsoft.SharePoint.SPWebCollection allWebs1 ,MAPILab.SharePoint.Explorer.CodeForm.MLCodeForm thisForm ,MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.MLBrowser browser ) { allWebs1.Add("Sample"); // Output browser configuration //browser.Text = "Browser window"; //browser.DisplayMode = MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.DisplayMode.Expanded; browser.ReturnValue = allWebs1["Sample"]; } }
Visual Basic Imports System Imports System.Collections.Generic Imports System.Diagnostics Imports System.Text Imports MAPILab.SharePoint.Explorer.CodeForm Imports MAPILab.SharePoint.Explorer.Utilities.ScriptRunner Public Class Tester Shared Sub Main(ByVal allWebs1 As Microsoft.SharePoint.SPWebCollection, ByVal thisForm As MAPILab.SharePoint.Explorer.CodeForm.MLCodeForm, ByVal browser As MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.MLBrowser) allWebs1.Add("Sample") ' Output browser configuration 'browser.Text = "Browser window" 'browser.DisplayMode = MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.DisplayMode.Expanded browser.ReturnValue = allWebs1("Sample") End Sub End Class
После выполнения сценария, информация о только что созданном веб-узле будет показана в новом окне браузера. Не закрывайте это окно – оно понадобится нам в следующем примере!