Let's assume we have a simple structure for our content, e.g.:
home --products ----product 1 ----product 2 --services --about us --...
Trying to copy "home" using Document.Copy() works fine, but also copies all child documents, which is something I do not want. Is there any way to "ignore" childen when copying?
I would have expected some optional parameter for Document.Copy() that enables / disables recursion, but there seems to be none.
yes, his making-a-mess-and-cleaning-up-again-in-two-easy-steps ;-)), came to my mind, too. But: If I want to copy Home AND products (one level below Home) but I do not want to copy "services" and "about us", this approach is gettings *really* messy ...
It would be nice if anyone from forum can help on this!
Seems as if there is nobody out there to help ... ?
Ok, what I did is ... :
- Got the sourcecode for Umbraco 4.11...
- Went to umbraco.cms.businesslogic.web.Document
- introduced a 4th paramter for Copy(): bool CopyChildren
public Document Copy(int CopyTo, User u, bool RelateToOrignal, bool CopyChildren) { ... }
- Somewhere at the end of the method there is a recursive call to copy all children. Using the new paramter CopyChildren changed this fragment as follows:
if (CopyChildren) { (...) d.Copy(newDoc.Id, u, RelateToOrignal, true); (...) }
- introduced a new method with the signature of the "old" Copy-method so that I don't break any existing functionality / tests:
public Document Copy(int CopyTo, User u, bool RelateToOrignal) { return this.Copy(CopyTo, u, RelateToOrignal, true); }
This is it.
Standard behaviour for Document.Copy() copies all child documents, a new method with a 4th paramter which specifies, if child documents should be copied, is also available so that rare cases like mine can also be implemented.
I have no idea how to submit this code back to the umbraco-repository, but I will try to find out ...
Document.Copy() without copying child documents
Let's assume we have a simple structure for our content, e.g.:
home
--products
----product 1
----product 2
--services
--about us
--...
Trying to copy "home" using Document.Copy() works fine, but also copies all child documents, which is something I do not want. Is there any way to "ignore" childen when copying?
I would have expected some optional parameter for Document.Copy() that enables / disables recursion, but there seems to be none.
Umbraco 4.11
Hi Stefan,
I had the same issue few months back, coudn't able to find any solution yet, always had to delete children of newly created document.
if (newDoc.ChildCount > 0)
{
foreach (var childDocs in newDoc.Children)
{
childDocs.delete(true);
}
}
It would be nice if anyone from forum can help on this.
Thanks
Sahan
Hello Sahan
yes, his making-a-mess-and-cleaning-up-again-in-two-easy-steps ;-)), came to my mind, too. But: If I want to copy Home AND products (one level below Home) but I do not want to copy "services" and "about us", this approach is gettings *really* messy ...
It would be nice if anyone from forum can help on this!
Stefan
Seems as if there is nobody out there to help ... ?
Ok, what I did is ... :
- Got the sourcecode for Umbraco 4.11...
- Went to umbraco.cms.businesslogic.web.Document
- introduced a 4th paramter for Copy(): bool CopyChildren
- Somewhere at the end of the method there is a recursive call to copy all children. Using the new paramter CopyChildren changed this fragment as follows:
- introduced a new method with the signature of the "old" Copy-method so that I don't break any existing functionality / tests:
Hi,
I have the same problem and applied the solution proposed above, except that I'm using Umbraco V6.
More détails in http://our.umbraco.org/forum/developers/extending-umbraco/44763-using-DocumentCopy-to-move-a-page-keeping-the-tree-structure
is working on a reply...