<<previous next>>

Operations with persisted objects

Windows SharePoint Services 3.0 and Microsoft Office SharePoint Server 2007 contain a lot of different settings. These are settings of various services, connection strings for databases, indexing parameters, and administrative settings – this list can be continued for a long time.

Storage of majority of SharePoint settings is realized very smartly – developers used the opportunity that .NET objects can be easily serialized and deserialized. Data stream obtained after serialization is saved in the Objectstable of the configurational database (as a rule, it`s name starts with SharePoint_Config__). If restoration of saved object condition is necessary, saved data is read from the mentioned table and used for deserialization.

All types saved in the configurational database are inherited from the type Microsoft.SharePoint.Administration.SPPersistedObject. These types can be developed by either the Microsoft Company itself, or by any other third-party developers.

Persisted objects form a hierarchy. The base of this hierarchy is an object of type SPFarm – SharePoint farm object. It is simple to make sure of that by selecting objects with Id = ParentId from the table. Because of this, hierarchy of persisted objects always can be presented similarly to Windows registry or hierarchy of Active Directory objects.

In the browser, all objects inherited from SPPersistedObject are marked with icon image003.png.

Due to special importance of this object type, MAPILab Explorer for SharePoint offers three modes of operations with them:
  1. Access to parent object by means of property SPPersistedObject.Parent.
  2. Access to child objects by means of special node in the object tree – Persisted Children.
  3. Creation of script for direct access to persisted object.

As first and second modes needn`t to be commented, let us pay attention to the third mode. It is very important, since, as a rule, it is used when developing solutions for SharePoint.

Suppose that you need to know exactly which folder is used for storing log-files. By performing a simple search in documentation for Windows SharePoint Services 3.0 included in Windows SharePoint Services 3.0 SDK, we discover that path to folder of log-files is kept in property LogLocation of class SPDiagnosticsService. There we also find that class SPDiagnosticsServices has the following constructor:

SPDiagnosticsService (String, SPFarm)

Such constructor has all persisted objects of SharePoint. Since there can be only one object SPDiagnosticsServices in SharePoint farm, parameter name is not needed for it`s creation – it can equal to "". Second parameter – parent – is absolutely necessary; it can be taken from object browser by flagging object of type SPFarm.

After flagging object of type SPFarm and creating new script window, the program generates the following script code:
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.Administration.SPFarm sPFarmNameSharePoint1
        ,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 sPFarmNameSharePoint1 As Microsoft.SharePoint.Administration.SPFarm, 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

Modify it so that, when executing it, object SPDiagnosticsServices is created, value of property LogLocation is place in output box, and method main will return created object for further investigation:
C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using MAPILab.SharePoint.Explorer.CodeForm;
using MAPILab.SharePoint.Explorer.Utilities.ScriptRunner;
using Microsoft.SharePoint.Administration;

public class Tester
{
    static void Main(
         Microsoft.SharePoint.Administration.SPFarm sPFarmNameSharePoint1
        ,MAPILab.SharePoint.Explorer.CodeForm.MLCodeForm thisForm
        ,MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.MLBrowser browser
        )
    {
        // Create new SPDiagnosticsService object 
        SPDiagnosticsService diagService = new SPDiagnosticsService("", sPFarmNameSharePoint1); 
        
        // Output log-files location 
        Debug.Print("Log-files store: {0}", diagService.LogLocation);
        
        // Output browser configuration
        //browser.Text = "Browser window";
        //browser.DisplayMode = MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.DisplayMode.Expanded;
        browser.ReturnValue = diagService;
    }
}
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
Imports Microsoft.SharePoint.Administration

Public Class Tester
    Shared Sub Main(ByVal sPFarmNameSharePoint1 As Microsoft.SharePoint.Administration.SPFarm, ByVal thisForm As 
        MAPILab.SharePoint.Explorer.CodeForm.MLCodeForm, ByVal browser As MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.MLBrowser)
        ' Create new SPDiagnosticsService object 
        Dim diagService As SPDiagnosticsService = new SPDiagnosticsService("", sPFarmNameSharePoint1)  
        
        ' Output log-files location 
        Debug.Print("Log-files store: {0}", diagService.LogLocation)
        
        ' Output browser configuration
        'browser.Text = "Browser window"
        'browser.DisplayMode = MAPILab.SharePoint.Explorer.Utilities.ScriptRunner.DisplayMode.Expanded
        browser.ReturnValue = diagService
    End Sub
End Class

As a result of script execution, the following information will be placed in output box

Build started...
Compile complete -- 0 errors, 0 warnings
Running method main...
Log-files store: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS\
Operation complete!

After that, the object diagService itself will be shown in new browser window.


<<previous next>>

Contents

Last edited Nov 2, 2009 at 2:10 PM by EugenMakarkhin, version 6

Comments

No comments yet.