Can you explain the full context of your scenario, it may be that what you are trying to do does not need to be done in action handler but xslt and template?
We try to send with an event handler a mail to an user when he has a new entry in his node. The user gets the mail, but the NiceUrl (e.g. www.domain.ch/products.aspx) is missing. Here a short part of the code.
...
Document currentDoc = new Document(sender.Id);
if (currentDoc != null) {
Node parentCmsNode = new Node(currentDoc.Parent.Id);
if (parentCmsNode != null) {
StringBuilder sb = new StringBuilder();
sb.AppendLine("Live-Url: www.domain.ch" + ???);
...
}
var url = umbraco.library:NiceUrl(currentNode.Id);
(Be aware tho that this might be a relative path if useDomainPrefix is set to false (umbracoSettigns.config) - Changing this to "true" will get you the complete path in combination if you've also set the domain name on the top level node using 'Manage hostnames')
If at the time of event the document is not published then niceurl will not work, also you dont need todo the extra new document call you already have the document namely sender. Think there is post publish event do the niceurl there becuase then doc is published. One thing when you say dont work do you get error?
if you want to send an email with the link after a node has been published then this should work (just tried out to be sure):
using System.Text; using umbraco.BusinessLogic; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.web;
namespace Application { public class DocumentEvent : ApplicationBase { public DocumentEvent() { Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish); }
Why don't you just use the built in notification system? That has quite a few different events which you can subscribe to, including publish, which will send an email
We are still trying to get the “Nice URL” of a new created node in the Document_AfterPublish event. It’s no problem no catch it when you push the “Publish button” a second time. But the first time the result is just an empty string (umbraco.library.NiceUrl(sender.Id) == String.Empty).
As far as I can tell, (from my limited knowledge of the core code), the filesystem XML cache (in /data/umbraco.config) is not updated with the Document.Publish method (it happens elsewhere - not sure where - but it doesn't happen here).
So, since NiceUrl uses the XML cache (via the filesystem), you can't get the URL in the AfterPublish event.
What you need to do is manually update the XML document cache like this:
I looked through the source (via Reflector) to see where the UpdateDocumentCache is called and it's by the Publish on the editContent control (ref: "umbraco.cms.presentation.editContent.Publish").
So using it in your Event handler will be calling it twice ... but I guess that's a small overhead for your desired result! So it's worth it!
How to get currentNode in the PublishEventHandler
Hi Umbracians
How I can get the currentNode in the PublishEventHandler? I have tried
Node currentNode = new Node(sender.Id);
but this don't work for me...
The first parameter of the PublishEventHandler is the actual Document on which this event is performed.
Take a look into the wiki: http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events
hth, Thomas
Thanks for your reply Thomas, but this is not my problem ;-)...
Calvin,
Take a look at http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-a-node-and-a-document in action handler you use the document becuase you already have it passed to you.
Regards
Ismail
We would like to offer a link to the frontend (something like node.NiceUrl) in the event handler.
Calvin,
Can you explain the full context of your scenario, it may be that what you are trying to do does not need to be done in action handler but xslt and template?
Regards
Ismail
Okay sorry for my small descripton :-).
We try to send with an event handler a mail to an user when he has a new entry in his node. The user gets the mail, but the NiceUrl (e.g. www.domain.ch/products.aspx) is missing. Here a short part of the code.
We have tried
and
and more...
Hi,
NiceUrl will give you the path to the node
(Be aware tho that this might be a relative path if useDomainPrefix is set to false (umbracoSettigns.config) - Changing this to "true" will get you the complete path in combination if you've also set the domain name on the top level node using 'Manage hostnames')
Hope this helps.
Cheers,
/Dirk
Thanks Dirk for your solution, but
don't work :-/.
Calvin,
If at the time of event the document is not published then niceurl will not work, also you dont need todo the extra new document call you already have the document namely sender. Think there is post publish event do the niceurl there becuase then doc is published. One thing when you say dont work do you get error?
Regards
Ismail
We already firing with Document.AfterPublish. No we don't get an error only an empty string.
Calvin
Hi Calvin,
if you want to send an email with the link after a node has been published then this should work (just tried out to be sure):
AfterPublish you will be able to use the id of the node (published document) to get the Url with this line: umbraco.library.NiceUrl(sender.Id)
- Morten
Why don't you just use the built in notification system? That has quite a few different events which you can subscribe to, including publish, which will send an email
@ Morten
Thank you for your solution, but i become the Url (e.g. www.domain.ch/products.aspx) as recently as I publish the node twice.
@ slace
We do not want to create backend users...
We are still trying to get the “Nice URL” of a new created node in the Document_AfterPublish event. It’s no problem no catch it when you push the “Publish button” a second time. But the first time the result is just an empty string (umbraco.library.NiceUrl(sender.Id) == String.Empty).
Any ideas?
Hi Calvin and Tobias,
As far as I can tell, (from my limited knowledge of the core code), the filesystem XML cache (in /data/umbraco.config) is not updated with the Document.Publish method (it happens elsewhere - not sure where - but it doesn't happen here).
So, since NiceUrl uses the XML cache (via the filesystem), you can't get the URL in the AfterPublish event.
What you need to do is manually update the XML document cache like this:
Good luck, Lee.
Hi Lee your solution is perfect and get the desired effect! Thank you a lot!
Hi Calvin, glad that it worked! :-)
I looked through the source (via Reflector) to see where the UpdateDocumentCache is called and it's by the Publish on the editContent control (ref: "umbraco.cms.presentation.editContent.Publish").
So using it in your Event handler will be calling it twice ... but I guess that's a small overhead for your desired result! So it's worth it!
Cheers, Lee.
Just thought of a better solution... hook into the "AfterUpdateDocumentCache" event instead!
This happens after the XML cache is regenerated. It's also where the old ActionPublish handler is... which makes so much more sense!
I guess the naming convention of "Document.AfterPublish" makes developers go straight for that, whereas "AfterUpdateDocumentCache" isn't so obvious!
Cheers, Lee.
is working on a reply...