Monday, January 20, 2014

Advantages of SPPersistedObject: Good performance by Direct SharePoint caching mechanisms storing t


When it comes to storing custom harris scarfe catalogue data in SharePoint, there are several ways you know, (a small overview can be found here) depending on the purpose they all have their pros and cons.
Advantages of SPPersistedObject: Good performance by Direct SharePoint caching mechanisms storing the data in the config database from SharePoint harris scarfe catalogue Backup-/Restore-Unterstützung by implementing harris scarfe catalogue the interface IBackupRestore
Here are a few more facts of this class: namespace of the class: Microsoft.SharePoint.Administration The class serves as the base class for many SP objects, especially in the administration area data as an XML BLOB in the database The class is to implement the so-called "Hierarchical Object Store" used The class provides a persistent SPPropertyBag, a Hashtable indexed for filing the objects are available to all services of the farm are available, regardless of the parent object Basic declaration
using System; using Microsoft.SharePoint.Administration; namespace Impuls.SharePoint.Extensions.WebTracking.Config {public class DataObject: SPPersistedObject {[Persisted] public string data = string.Empty; harris scarfe catalogue public DataObject () {} public DataObject (string name, SPPersistedObject parent, Guid id): base (name, parent, id) {} public DataObject (string name, SPPersistedObject parent): base (name, parent) {}}}
Where it is important in this case is one of the parameterized constructors including base-calling as well as to define the parameterless constructor, because it is used during deserialization of the object. There is a constructor for the case that you do not want the ID of the object determine. In this case, a new GUID for the object is automatically created, which of course can still be queried afterwards. The Persisted attribute
The crux of the above declaration is the Persisted attribute is used which are persistent, that is to be permanently marked in the database data to be stored. With respect to the attribute, there are two things to consider: It can be applied only to public fields, not properties, it can only be used for primitive types, ie for string, int, GUID, Hashtable, enumerations, etc.
If no public field of the class is equipped with this attribute only the PropertyBag is stored permanently. Furthermore, other SPPersistedObject objects can (and lists thereof) who will act as fields harris scarfe catalogue of the class with this attribute to them mitzuspeichern automatically.
If you what can happen quite quickly or has the Hierarchical Object Store once corrupted by having used a complex type or similar, this article will help further: Repairing the Hierarchical Object Store initialization and use
IMPORTANT NOTE To execute the Update (), Delete () and Unprovision () methods must be the code in the context of a user who is both farm administrator as well as access to the database harris scarfe catalogue has SharePoint_Conf. If the code inside the Central Administration harris scarfe catalogue of SharePoint running, or within a content-WebApplication that has the same service or application pool account as the CA, it is sufficient to code within a RunWithElevatedPrivileges statement to execute, otherwise to SQL or Security Exceptions coming!
/ / Properties of the object SPWebApplication parent = SPContext.Current.Site.WebApplication; Guid id = new Guid ("2BF59217-A6D4-4333-8DB9-27BBC6313E18"); string name = "MyDataObject"; / / Initialization Data Object DataObj harris scarfe catalogue = new DataObject (name, parent, id) / / assigning values dataObj.data = "foo" / / assigning values in the PropertyBag dataObj.Properties.Add ("MyKey", "bar"); / / Save the values DataObj. update harris scarfe catalogue () / / delete the object dataObj.Delete (); dataObj.Unprovision ();
Important here is the allocation of its parent object and the use of dedicated methods harris scarfe catalogue to store values in the database and delete the entire object from the database. As a parent objects all derived from SPPersistedObject classes come in question, which include the majority of the defined in the namespace Microsoft.SharePoint.Administration classes.
/ / General harris scarfe catalogue retrieve a SPFarm object SPFarm harris scarfe catalogue farm = SPFarm.Local; DataObject DataObj = (DataObject) farm.GetObject (new Guid ("2BF59217-A6D4-4333-8DB9-27BBC6313E18")); / / Retrieve the context of close up on the Parent SPWebApplication object parent = SPContext.Current.Site.WebApplication; DataObject DataObj = parent.GetChild <DataObject> (name);
Conclusion The SPPersistedObject or its derived classes are ideally suited to hierarchically oriented data in SharePoint own "Hierarchical harris scarfe catalogue Object Store" to permanently save and convenient to use. Through its farm-wide availability, the classes are

No comments:

Post a Comment