GenericContent - for Developers

From Sense/Net Wiki
Jump to: navigation, search
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned


GenericContent class is the content handler of the GenericContent content type. Since the GenericContent is the top level type, its content handler is the top level content handler in the class hierarchy of content handlers - it is the first direct child of the node base class. Its importance lies in the features defined as its public functions making it a more handy API to use for regular content operations than the node API.


Why use GenericContent instead of Node?

The GenericContent class extends the node API with some elementary functionality for which reason it is recommended to use GenericContent (or a class inheriting from it) as the base Content Handler for any type and also use the GenericContent API when working with content from code. These are:

  • versioning functions: public functions specialized for versioned saving of content are implemented in the GenericContent class,
  • property routing: any new Fields added to the CTD of the Content Type will function even without modifying the code of the type's content handler. This automatic routing is implemented in the GenericContent class.

Loading content

The easiest way to load a content from the repository and use the GenericContent API is to load the content as a node and then cast it to GenericContent:

var gc = Node.LoadNode("/Root/Sites/Default_Site/myContent") as GenericContent;

If the specified content does not exist Node.LoadNode will return with null.

Operations with GenericContent

Since GenericContent inherits from the base Node class, all of Node's functionality is available here as well: modifying properties, copying, moving, deleting, etc. Please refer to the documentation of the Node API for further information:


For versioned saving of a content you can use the following functions:

gc.CheckOut(); // checks out the content to the current user
gc.UndoCheckOut(); // undos changes by the current user
gc.ForceUndoCheckOut(); // undos changes made by another user
gc.CheckIn(); // checks in the content
gc.Publish(); // publishes the content (only in major&minor versioning)
gc.Approve(); // approves the content
gc.Reject(); // rejects the content

Calling content.Save() will save the content in the appropriate version according to the versioning of the content. You can use the SaveSameVersion in order to save changes on the current version:

// versioning: none
gc.Save(); // from 1.0A to 1.0A
gc.Save(SavingMode.KeepVersion); // from 1.0A to 1.0A
// versioning: major
gc.Save(); // from 1.0A to 2.0A
gc.Save(SavingMode.KeepVersion); // from 1.0A to 1.0A
// versioning: major and minor
gc.Save(); // from 1.0A to 1.1D, from 1.1D to 1.2D, etc..
gc.Save(SavingMode.KeepVersion); // from 1.0A to 1.0A, from 1.1D to 1.1D, etc..

Calling content.Save() on a locked content will always save on the current version:

// gc.Locked == true
gc.Save(); // from 2.0L to 2.0L, from 1.1L to 1.1L, etc..

There are also some helper properties to determine the current state of the content:

gc.Approvable; // true if content is approvable
gc.Publishable; // true if content is publishable
gc.IsLatestVersion; // true if content object corresponds to the latest version
gc.IsLastPublicVersion; // true if content object corresponds to the last public version

Creating content

To create content using the GenericContent API use the following syntax:

var parent = Node.LoadNode("/Root/IMS/Builtin/Portal");
var user = new GenericContent(parent, "User");
user.Name = "newuser";

To see other ways of creating content, read Node - for Developers and Content - for Developers.

GenericContent and node

The GenericContent is the most basic content type in the content repository. The GenericContent class is the content handler for the top-level content type (is derived from the Node base class) and thus all of our content handlers are derived from GenericContent. To read more about the abstract node class, click here:


There are no examples for this article.

Related links


There are no related external articles for this article.