Hi, I have a page called News and I am creating folders for each year and adding document of page type CMS.News under each year folder. I do not want to have each news detail page to have url as /News/2019/SomeNewsTitle. So in CustomInitializationModule file, I wrote the following code.
protected override void OnInit() { base.OnInit(); DocumentEvents.Insert.Before += SetDocumentURL; DocumentEvents.Update.Before += SetDocumentURL; } private void SetDocumentURL(object sender, DocumentEventArgs e) { TreeNode node = e.Node; if (node.ClassName.ToLower() == "CMS.News") { var doc = DocumentHelper.GetDocument(node.NodeID, new TreeProvider()); if (doc != null) { node.DocumentUrlPath = "/News/" + node.DocumentName; node.DocumentUseNamePathForUrlPath = false; node.Update(); } } }
Note: Workflow and Versioning is enabled.
So when I create a new page, it sets correct path in Properties -> Urls. The problem is when I update the document name it does not update the path in Properties -> Urls
What am I doing wrong?
Thanks
Hi Shweta,
This is just a start. If the documents are under workflow, you need to use events from the WorkflowEvents class instead of DocumentEvents. For example, to handle when the document is updated use the SaveVersion event.
Mike
Or, you do not need to use Workflow events, just use the workflow API in the handler code to properly create and save given version of the page.
Please, sign in to be able to submit a new answer.