Unable to change document name in Document.AfterSave
Hi
Im trying to change the name of the document I'm publishing using Document.Aftersave, but it doesn't seem to work - the name doesn't get changed.
Document CurrentDocument = new Document(sender.Id); CurrentDocument.Text = "Change name to this"; CurrentDocument.Publish(new User(0)); umbraco.library.UpdateDocumentCache(sender.Id);
The funny thing is, that is works if I only save and then publish afterwards, but I can't rely on the client doing that.
Is it because I do it while publishing the document?
Try directly interacting with the 'sender' object, rather than creating a new one. The sender object is mutable and I think your problem is that the Save event hasn't completed so it'll trash what you're try to set once the event handler is completed
Unable to change document name in Document.AfterSave
Hi
Im trying to change the name of the document I'm publishing using Document.Aftersave, but it doesn't seem to work - the name doesn't get changed.
The funny thing is, that is works if I only save and then publish afterwards, but I can't rely on the client doing that.
Is it because I do it while publishing the document?
Regards Kingo
Try directly interacting with the 'sender' object, rather than creating a new one. The sender object is mutable and I think your problem is that the Save event hasn't completed so it'll trash what you're try to set once the event handler is completed
That did the trick.
It's enogh to change the Text, no need for Publish or UpdateDocumentCache
Thanks
is working on a reply...