This project is read-only.

Create Copy content Item

Topics: Writing modules
Sep 24, 2012 at 2:41 PM

I need button to create copy of any content item.

Its my be content part with copy button or something else.

Have any ideas how I can do it?

Sep 24, 2012 at 4:58 PM

It's not trivial for arbitrary content types but one thing that could be done would be to leverage the import/export APIs to create a new item with the same data but a different ID.

Sep 28, 2012 at 1:11 PM
Edited Sep 28, 2012 at 1:11 PM

bertrandleroy, your advice helped me, thanks!

Now i have working version.

I create a part that dispaly my copy link about view, unpublish, edit, delete link in summary admin. I can display it after unpublish and edit link by <Place Parts_Copy_SummaryAdmin="Actions:6"/>. But how i can display this part after edit, delete link? Can i use designer module for dashboard?

Copy link point to controller action


public ActionResult Copy(int id, string returnUrl)
            var contentItem = _contentManager.GetLatest(id);

            if (contentItem == null)
                return HttpNotFound();

            if (!Services.Authorizer.Authorize(Permissions.EditContent, contentItem, T("Couldn't edit content")))
                return new HttpUnauthorizedResult();

            var importContentSession = new ImportContentSession(Services.ContentManager);
            var element = _contentManager.Export(contentItem);
            var elementId = element.Attribute("Id");
            elementId.SetValue(elementId.Value + "-copy-" + Guid.NewGuid());

            var identity = elementId.Value;
            var status = element.Attribute("Status");
            importContentSession.Set(identity, element.Name.LocalName);

            _contentManager.Import(element, importContentSession);

            return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));


It is working way but it needs some work. If anyone would complement this code, I will be very grateful.

Sep 30, 2012 at 7:55 PM

The way you handle id does not look right to me, it seems like it could result in unpredictable behavior, depending on the identity provider(s) that end up being used on that content type.

The existing buttons are already contributed by various pieces of code. Look at how the publish button is added only when the type is draftable for example.