I'm trying to build an event handler that moves a document to a date specifik folder when saving and publishing the document for the first time. I assumed the Published property on the document would be true, when the document has been published once.
What I'm trying to to is prevent HandleCupcakeBeforeSave from running after the document in question has been published elsewhere. If I don't do that the method will run on every save and publish (since publishing alse triggers a save), thereby moving the document to the current date.
If sender.Published was true when the document being saved is already published, I could use this property to prevent moving already published documents.
insteed of using the save or publish handler, you can use the document_xxxnew handler, so that way you are sure that the document will be moved only once at the creation.
Yah ! No idea, I didn't worked with this property yet... Try with doc.HasPublishedVersion() ? Maybe the Published setting is only valid for the current document verson, in that way, it could be logic that if you edit and Save. The Published property is set to false, as the current version of the document need to be published before it is visible on the frontend.
On the other hand in the eventhandler beforeSave the published property could not be set to false as it is not yet saved. The published property should be set to false afterSave. So maybe the published is set somewhere between when you push the edit button and the beforesave handler... But this can only be told by a such umbraco guru that is definitely not hanging on the umbraco forums :-)
Using document.Published in an event handler
I'm trying to build an event handler that moves a document to a date specifik folder when saving and publishing the document for the first time. I assumed the Published property on the document would be true, when the document has been published once.
I'm using the following code:
But it seems sender.Published is false even when the document being saved is published. Is there something I am missing?
Regards
Jesper Hauge
Saving is not Publishing !
@Laurent:
I'm aware of that! Publishing occurs later.
What I'm trying to to is prevent HandleCupcakeBeforeSave from running after the document in question has been published elsewhere. If I don't do that the method will run on every save and publish (since publishing alse triggers a save), thereby moving the document to the current date.
If sender.Published was true when the document being saved is already published, I could use this property to prevent moving already published documents.
.Jesper
insteed of using the save or publish handler, you can use the document_xxxnew handler, so that way you are sure that the document will be moved only once at the creation.
D'oh - I forgot to check for an event like that - that will do the trick. Thanks Laurent.
But I still find it a bit odd that the sender.Published property is always false ...
.Jesper
Yah ! No idea, I didn't worked with this property yet... Try with doc.HasPublishedVersion() ? Maybe the Published setting is only valid for the current document verson, in that way, it could be logic that if you edit and Save. The Published property is set to false, as the current version of the document need to be published before it is visible on the frontend.
On the other hand in the eventhandler beforeSave the published property could not be set to false as it is not yet saved. The published property should be set to false afterSave. So maybe the published is set somewhere between when you push the edit button and the beforesave handler... But this can only be told by a such umbraco guru that is definitely not hanging on the umbraco forums :-)
is working on a reply...