DataProvider is the class that must be inherited when building a custom data provider.
The list of methods available on this class is pretty expansive. A small number of the methods must be implemented in order to get a working data provider. The functionality you need will determine the methods you must implement.
For read-only data providers you must implement:
For read/write data providers you must implement:
For read/write data providers that support versioning you must implement:
Returns a collection of IDs that represents the Sitecore items that are children of a specific Sitecore item.
ItemDefinition - the Sitecore item whose children are being retrievedCallContextIDList containing the IDs of the childrennull or empty IDList object nullpublic override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
{
if (itemDefinition.ID == MyItemIDs.MyProviderRoot)
{
var ids = new IDList();
ids.Add(MyItemIDs.Child1);
ids.Add(MyItemIDs.Child2);
ids.Add(MyItemIDs.Child3);
return ids;
}
return null;
}
Returns an object that describes the Sitecore item that corresponds to a specific Sitecore item ID.
ID - the ID of the Sitecore item whose definition is being retrievedCallContextID: ItemDefinition objectID: nullpublic override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
{
ItemDefinition itemDef = null;
if (itemId == MyItemIDs.MyProviderRoot)
{
itemDef = new ItemDefinition(itemId, "My Provider Root", TemplateIDs.Folder, ID.Null);
}
else if (itemId == MyItemIDs.Child1)
{
itemDef = new ItemDefinition(itemId, "Child1", TemplateIDs.File, ID.Null);
}
else if (itemId == MyItemIDs.Child2)
{
itemDef = new ItemDefinition(itemId, "Child2", TemplateIDs.File, ID.Null);
}
else if (itemId == MyItemIDs.Child3)
{
itemDef = new ItemDefinition(itemId, "Child3", TemplateIDs.File, ID.Null);
}
return itemDef;
}
Returns a collection of information that identifies the fields that populate the a specific version of a specific Sitecore item.
ItemDefinition - the Sitecore item whose fields are being retrieved VersionUri - the version of the Sitecore item whose fields are being retrievedCallContextFieldList containing the IDs of the childrennull or empty IDList object nullThe following example demonstrates a data provider that does not support versioning. The same field values are returned regardless of the VersionUri parameter:
public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
{
if (itemId == MyItemIDs.MyProviderRoot ||
itemId == MyItemIDs.Child1 ||
itemId == MyItemIDs.Child2 ||
itemId == MyItemIDs.Child3)
{
var now = Sitecore.DateUtil.ToIsoDate(DateTime.Now);
var fields = new FieldList();
fields.Add(FieldIDs.Created, now);
fields.Add(FieldIDs.Updated, now);
fields.Add(FieldIDs.Owner, this.Owner);
fields.Add(FieldIDs.CreatedBy, "custom data provider");
fields.Add(FieldIDs.UpdatedBy, "custom data provider");
return fields;
}
return null;
}
Returns a collection of VersionUri objects that represent the versions available for a specific Sitecore item.
ItemDefinition - the Sitecore item whose versions are being retrieved CallContextVersionUriList containing the VersionUri objects that represent the available versionsnull or empty VersionUriList object nullThe following example demonstrates a data provider that does not support versioning. It always returns one version for each language defined in the Sitecore database:
public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context)
{
if (itemId == MyItemIDs.MyProviderRoot ||
itemId == MyItemIDs.Child1 ||
itemId == MyItemIDs.Child2 ||
itemId == MyItemIDs.Child3)
{
var versions = new VersionUriList();
foreach (var language in context.DataManager.Database.Languages)
{
versions.Add(language, Sitecore.Data.Version.First);
}
return versions;
}
return null;
}
Returns the languages that are supported by the data provider.
In most cases this method should be overridden to return null. The default data provider will return the appropriate languages. Failing to implement the method properly will result in duplicate languages appearing:

CallContextLanguageCollection containing the Language objectsnull or empty LanguageCollection object nullThe following example demonstrates a data provider that does not add support for any additional languages:
public override LanguageCollection GetLanguages(CallContext context)
{
return null;
}
Returns the ID that represents the Sitecore item that is the parent of a specific Sitecore item.
ItemDefinition - the Sitecore item whose parent is being retrievedCallContextID for the parent Sitecore itemSitecore.Data.ID.Nullpublic override ID GetParentID(ItemDefinition itemDefinition, CallContext context)
{
if (itemId == MyItemIDs.Child1 ||
itemId == MyItemIDs.Child2 ||
itemId == MyItemIDs.Child3)
{
return MyItemIDs.MyProviderRoot;
}
return ID.Null;
}