| This post was migrated from an older system. Some links may point to content that no longer exists. Comments were not migrated.
Question:
Do you know anything about…
…in the SDK that under the Microsoft.SharePoint.Administration namespace that “The new hierarchical object store provides a common framework for third-party applications to manipulate and store administrative data”…
Can we use this to store our own data?
Answer:
Yes! Unfortunately, the documentation is pretty weak in this area. The hierarchical object store is the mechanism by which WSS itself uses to store information about the farm, web applications, features, etc. The great thing is that you, the developer, can also use the store to build and store information.
How does it work?
It's a two step process...
- Create a class which inherits from
Microsoft.SharePoint.Administration.SPPersistedObject
- Use the Administration namespace to add, retrieve, or remove the object from the
store
Let's take a look custom class designed to hold some values...
/// <summary>
/// Class - The Counter class is simple class that is used to store a numeric value
/// </summary>
public class Counter : Microsoft.SharePoint.Administration.SPPersistedObject {
[Microsoft.SharePoint.Administration.Persisted]
public int Number = 99;
/*
// ----------------------------------------------------------------------
// Note: PersistedAttribute cannot be use with properties. Boo! V4? Please?
// ----------------------------------------------------------------------
public int Number {
get {
return number;
}
set {
number = value;
}
}
*/
// ----------------------------------------------------------------------
// Note: A default public constructor is necessary for serialization.
// If not provided, WSS will not be able to utilize this class.
// ----------------------------------------------------------------------
public Counter () {
} // End of Counter constructor
// ----------------------------------------------------------------------
// Parameterized constructor is called by WSS runtime to initialize the class
// ----------------------------------------------------------------------
public Counter (string name, SPPersistedObject parent, Guid guid) : base (name,parent, guid) {
} // End of Counter constructor
} // End of Counter class
Now interact with the class...
// Designate a Guid value that uniquely represents my Counter object...
Guid storeGuid = new Guid ("{3C5C252B-6D11-4bc5-8DE6-E9D292D49BB5}");
// Designate which server will be utilized...
SPServer server = new SPServer ("westgate");
// Create a Counter object that is a child of the server farm...
// ----------------------------------------------------------------------
// Notes:
// 1 - the object can be parented against any other SPPersistedObject, in this
example the object is child of the farm
// 2 - the object must have a unique, non-changing Guid that identifies the object
within the entire scope of WSS
// ----------------------------------------------------------------------
Counter counter = new Counter ("My Counter", server.Farm, storeGuid);
// Update the field to a non-default value of 99...
counter.Number = 10000;
// Saves the object and push it out to all servers...
counter.Update();
// Now use a new object to prove the value was stored on the server...
Counter echo = (Counter) server.Farm.GetObject (storeGuid);
// Verify the object was stored with a non-default value...
System.Diagnostics.Debug.WriteLine ("This counter value should be 10,000: " + (echo.Number == 10000));
// Now delete the object...
echo.Delete ();
// And perform cleanup...
echo.Unprovision ();
There are few points worth mentioning...
- The PersistedAttriubute
class can only be used on fields. It would be nice to use
properties instead of fields but right now we're limited to fields...
- Two constructors are required in the SPPersistedObject-derivative
class. A public, default constructor and the parameterized form.
As you can imagine, there are a lot of possibilities with the hierarchical
store. Your objects can be parented against the farm, web application,
custom classes, etc.
Happy coding,
-Maurice
|
View in Web Browser
/SharePointThoughts/_layouts/VisioWebAccess/VisioWebAccess.aspx?listguid={ListId}&itemid={ItemId}&DefaultItemOpen=1
0x0
0x1
FileType
vdw
255
Manage Subscriptions
/_layouts/images/ReportServer/Manage_Subscription.gif
/SharePointThoughts/_layouts/ReportServer/ManageSubscriptions.aspx?list={ListId}&ID={ItemId}
0x80
0x0
FileType
rdl
350
Manage Data Sources
/SharePointThoughts/_layouts/ReportServer/DataSourceList.aspx?list={ListId}&ID={ItemId}
0x0
0x20
FileType
rdl
351
Manage Shared Datasets
/SharePointThoughts/_layouts/ReportServer/DatasetList.aspx?list={ListId}&ID={ItemId}
0x0
0x20
FileType
rdl
352
Manage Parameters
/SharePointThoughts/_layouts/ReportServer/ParameterList.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
rdl
353
Manage Processing Options
/SharePointThoughts/_layouts/ReportServer/ReportExecution.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
rdl
354
Manage Cache Refresh Plans
/SharePointThoughts/_layouts/ReportServer/CacheRefreshPlanList.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
rdl
355
View Report History
/SharePointThoughts/_layouts/ReportServer/ReportHistory.aspx?list={ListId}&ID={ItemId}
0x0
0x40
FileType
rdl
356
View Dependent Items
/SharePointThoughts/_layouts/ReportServer/DependentItems.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
rsds
350
Edit Data Source Definition
/SharePointThoughts/_layouts/ReportServer/SharedDataSource.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
rsds
351
View Dependent Items
/SharePointThoughts/_layouts/ReportServer/DependentItems.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
smdl
350
Manage Clickthrough Reports
/SharePointThoughts/_layouts/ReportServer/ModelClickThrough.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
smdl
352
Manage Model Item Security
/SharePointThoughts/_layouts/ReportServer/ModelItemSecurity.aspx?list={ListId}&ID={ItemId}
0x0
0x2000000
FileType
smdl
353
Regenerate Model
/SharePointThoughts/_layouts/ReportServer/GenerateModel.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
smdl
354
Manage Data Sources
/SharePointThoughts/_layouts/ReportServer/DataSourceList.aspx?list={ListId}&ID={ItemId}
0x0
0x20
FileType
smdl
351
Load in Report Builder
/SharePointThoughts/_layouts/ReportServer/RSAction.aspx?RSAction=ReportBuilderModelContext&list={ListId}&ID={ItemId}
0x0
0x2
FileType
smdl
250
Edit in Report Builder
/_layouts/images/ReportServer/EditReport.gif
/SharePointThoughts/_layouts/ReportServer/RSAction.aspx?RSAction=ReportBuilderReportContext&list={ListId}&ID={ItemId}
0x0
0x4
FileType
rdl
250
Edit in Report Builder
/SharePointThoughts/_layouts/ReportServer/RSAction.aspx?RSAction=ReportBuilderDatasetContext&list={ListId}&ID={ItemId}
0x0
0x4
FileType
rsd
250
Manage Caching Options
/SharePointThoughts/_layouts/ReportServer/DatasetCachingOptions.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
rsd
350
Manage Cache Refresh Plans
/SharePointThoughts/_layouts/ReportServer/CacheRefreshPlanList.aspx?list={ListId}&ID={ItemId}&IsDataset=true
0x0
0x4
FileType
rsd
351
Manage Data Sources
/SharePointThoughts/_layouts/ReportServer/DataSourceList.aspx?list={ListId}&ID={ItemId}
0x0
0x20
FileType
rsd
352
View Dependent Items
/SharePointThoughts/_layouts/ReportServer/DependentItems.aspx?list={ListId}&ID={ItemId}
0x0
0x4
FileType
rsd
353
Compliance Details
javascript:commonShowModalDialog('{SiteUrl}/_layouts/itemexpiration.aspx?ID={ItemId}&List={ListId}', 'center:1;dialogHeight:500px;dialogWidth:500px;resizable:yes;status:no;location:no;menubar:no;help:no', function GotoPageAfterClose(pageid){if(pageid == 'hold') {STSNavigate(unescape(decodeURI('{SiteUrl}'))+'/_layouts/hold.aspx?ID={ItemId}&List={ListId}'); return false;} if(pageid == 'audit') {STSNavigate(unescape(decodeURI('{SiteUrl}'))+'/_layouts/Reporting.aspx?Category=Auditing&backtype=item&ID={ItemId}&List={ListId}'); return false;} if(pageid == 'config') {STSNavigate(unescape(decodeURI('{SiteUrl}'))+'/_layouts/expirationconfig.aspx?ID={ItemId}&List={ListId}'); return false;}}, null); return false;
0x0
0x1
ContentType
0x01
898
Edit in Browser
/_layouts/images/icxddoc.gif
/SharePointThoughts/_layouts/formserver.aspx?XsnLocation={ItemUrl}&OpenIn=Browser&Source={Source}
0x0
0x1
FileType
xsn
255
Edit in Browser
/_layouts/images/icxddoc.gif
/SharePointThoughts/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser&Source={Source}
0x0
0x1
ProgId
InfoPath.Document
255
Edit in Browser
/_layouts/images/icxddoc.gif
/SharePointThoughts/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser&Source={Source}
0x0
0x1
ProgId
InfoPath.Document.2
255
Edit in Browser
/_layouts/images/icxddoc.gif
/SharePointThoughts/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser&Source={Source}
0x0
0x1
ProgId
InfoPath.Document.3
255
Edit in Browser
/_layouts/images/icxddoc.gif
/SharePointThoughts/_layouts/formserver.aspx?XmlLocation={ItemUrl}&OpenIn=Browser&Source={Source}
0x0
0x1
ProgId
InfoPath.Document.4
255
View in Browser
/SharePointThoughts/_layouts/xlviewer.aspx?id={ItemUrl}&DefaultItemOpen=1
0x0
0x1
FileType
xlsx
255
View in Browser
/SharePointThoughts/_layouts/xlviewer.aspx?id={ItemUrl}&DefaultItemOpen=1
0x0
0x1
FileType
xlsm
255
View in Browser
/SharePointThoughts/_layouts/xlviewer.aspx?id={ItemUrl}&DefaultItemOpen=1
0x0
0x1
FileType
xlsb
255
View in Browser
/SharePointThoughts/_layouts/xlviewer.aspx?id={ItemUrl}&DefaultItemOpen=1
0x0
0x1
FileType
ods
255