This project is read-only.

ItemEditor / versions

Topics: Developer Forum, User Forum
Mar 13, 2008 at 4:19 PM
Hi Christian,
I'm struggeling with the concepts of versioning with the ItemEditor. I have an separate edit page that I would like to insert a new item if an item with the requested name is not found, and update the item if it's found.

I have managed to insert a new item with VersioningMode = VersionAndSave.
If i try to update an item with the same VersioningMode it fails (An item named 'test' already exists below 'start').

If i set VersioningMode to SaveAsMaster it throws "Expected the current item to be a version of another item."

It seems that itemEditor.CurrentItem.VersionOf always is null in my case.

Any ideas? The code below is based upon your old BlogExample.

protected void Page_Load(object sender, EventArgs e) {
            if (!IsPostBack) {
	          itemEditor.ItemTypeName = typeof(PageItem).AssemblyQualifiedName;
                  if (Request.QueryString["item"] != null) {
                      try {
                          N2.ContentItem itm = N2.Find.Items.Where.Name.Like(Request.QueryString["item"].ToString()).Select()[0];
                          itemEditor.CurrentItem = itm;
                      catch {
                          // Item not found, new item...
protected void btnSave_Click(object sender, EventArgs e) {
		try {
                        itemEditor.CurrentItem.Parent = N2.Context.Current.UrlParser.StartPage;
                        itemEditor.VersioningMode = N2.Web.UI.WebControls.ItemEditorVersioningMode.VersionAndSave;
                        PageItem itm = (PageItem)itemEditor.CurrentItem;
		catch (N2.N2Exception ex) {
			cvSave.ErrorMessage = ex.Message;
			cvSave.IsValid = false;
Mar 13, 2008 at 7:57 PM
Maybe the itemeditor doesn't understand you're updating an existing item.

See if setting the current item oninit makes any difference:

	protected override void OnInit(EventArgs e)
		itemEditor.CurrentItem = GetExistingOrNewItem();

The versioningmode was useful to make it possible for customized editables to change the saving behaviour. Nowdays this is mostly controlled by the page. E.g:

  • ItemEditorVersioningMode.VersionAndSave: Store a version and save the item
  • ItemEditorVersioningMode.SaveAsMaster: Save a version as the published version
  • ItemEditorVersioningMode.VersionOnly: Store changes as a version but don't publish
  • ItemEditorVersioningMode.SaveOnly: Save changes to current item regardless of versioning

Are you building some kind of wiki?
Mar 13, 2008 at 10:26 PM
Thanks a lot! It works like it should now...
I must have been tired. Why didn't I try that?

As you suspected I'm building a simple wiki (or wiki-ish website). When I have a working example I'll send you the code if you like (I saw that a wiki is a remaining task in your todo-list).

N2 is really versatile. I'm using it for almost any web project nowadays. You are doing a truly amazing work Christian!

Mar 15, 2008 at 12:48 AM
Thanks =) and yes, I'd like the code.
Apr 25, 2008 at 10:46 AM
Hi again. Did you make any progress with the wiki?