Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • CASTELLI 23 posts 76 karma points
    Sep 13, 2013 @ 15:04
    CASTELLI
    0

    using Document.Copy to move a page keeping the tree structure

    Hi,

    What I'd like to achieve is the following:
    From within the backend, I've prevented writer and editor users to access the property tab of a node so that they don't mess up with the node definition, redirection, alias, ...
    I also do not want 'simple' users to mess up with the site principal hierarchy. So I have disabled the 'create' and 'move' options from the right click.
    But I still do want to allow them to be able to create an empty child node from the current or move the current content into a new child node.

    Here's what I've done :
    I created a user control and displayed it in my content tab of a specific document type with the Umbraco UserControl Wrapper datatype. This user control has a button to create a new child node from the current node. And a second button to move the content of the current node to a new child node, acting as a sort of archive mechanism where I can create fresh content in the current page and create a new page with the old content, keeping the same menu structure.

    My problem comes when I try to use Document.Copy(NodeId, User) in my user control's code behind. I think as I am creating a child from the current node, the Copy() gets into an infinite loop trying to copy all the current node sub nodes. Am I right ?
    If so how else can I do ?

    I know there is a Document.Move() method but that would break the menu structure.

    I wasn't too sure either on how to use the Copy() method, whether to put the current node ID like so:
      Document currDoc = new Document(iCurrNodeID);
      Document childPage = currDoc.Copy(iCurrNodeID, currUser);
    or create a new child first and give that child ID:
      Document currDoc = new Document(iCurrNodeID);
      Document childPage =   Document.MakeNew(txtNewName.Text, DocumentType.GetByAlias("s2k_pagesContenu"), currUser, iCurrNodeID);
      childPage = currDoc.Copy(childPage.Id, currUser);

    Please let me know, I'd like to be able to automate it and not have to copy all properties one by one into the new page.

    Thanks

  • CASTELLI 23 posts 76 karma points
    Sep 16, 2013 @ 16:27
    CASTELLI
    100

    I followed the advice on this post : http://our.umbraco.org/forum/developers/api-questions/39906-DocumentCopy()-without-copying-child-documents with an extra for V6 :

    The modification can be done in the Copy() method of the umbraco.cms.businesslogic.web namespace (Document.cs) as suggested in the above post.

    It must be done also in the Copy() method in the Umbraco.Core.Services namespace (ContentService.cs) and also update the signature references in IContentService.cs

    Rebuild and copy the new dll into your own project and web site.

Please Sign in or register to post replies

Write your reply to:

Draft