How do you get the Id of a newly copied document in the API
Hi,
Using the API I'm copying a document underneath the same parent folder as the original i.e. becoming a sibling.
I'd like to immediately publish the new document but I can't see how to get a reference to it. Document.Copy does not return the Id as I would have expected.
Any ideas how I can get either the new document or it's ID?
Thanks for the idea. Seems to work fine using relations. Basically after copying I loop through the pages relations and publish them then delete the relation. Obviously Im assuming there will only ever be one type of relation for this document type but in this situation that's fine.
Thanks again.
//Everyone forgets to put the namespaces in code snippetts!
using umbraco.cms.businesslogic.relation;
Document doc = new Document(1234);
doc.Copy(doc.Parent.Id,doc.User,true);
foreach (Relation r in Relation.GetRelationsAsList(doc.Id))
How do you get the Id of a newly copied document in the API
Hi,
Using the API I'm copying a document underneath the same parent folder as the original i.e. becoming a sibling.
I'd like to immediately publish the new document but I can't see how to get a reference to it. Document.Copy does not return the Id as I would have expected.
Any ideas how I can get either the new document or it's ID?
Document doc = new Document(1234);
doc.Copy(doc.Parent.Id,doc.User);
Thanks
DC
Hi Matt,
Few of ideas...
Let us know what you end up doing.
Cheers, Lee.
I've not used the relate to original functionality much so I'll take a quick look at the videos on umbraco.tv
I'm not keen on the third option as it's too risky on highly trafficked site but will look at it....
Thanks
DC
Lee,
Thanks for the idea. Seems to work fine using relations. Basically after copying I loop through the pages relations and publish them then delete the relation. Obviously Im assuming there will only ever be one type of relation for this document type but in this situation that's fine.
Thanks again.
//Everyone forgets to put the namespaces in code snippetts!
using umbraco.cms.businesslogic.relation;
Document doc = new Document(1234);
doc.Copy(doc.Parent.Id,doc.User,true);
foreach (Relation r in Relation.GetRelationsAsList(doc.Id))
{
Document newDoc = new Document(r.Child.Id);
newDoc.Publish(newDoc.User);
// Refresh runtime cache
umbraco.library.UpdateDocumentCache(newDoc.Id);
//Delete the relation
r.Delete();
}
Hi Matt, as Lee mentioned, the default RelationType alias for document copy is "relateDocumentOnCopy", so you can use:
Thanks Hendy. That will certainly clean up the code a little bit.
Thanks
DC
Excellent, glad the Relations API worked out... I'll make a copy of your code snippet for future reference!
Cheers, Lee.
Is there no proper answer to this? The solutions above are hacks, this seems really bizarre...
thanks.
I believe in the newer versions the Copy method returns a Document object of the newly copied document, ex:
is working on a reply...