C# 复制多语言umbraco站点保存时的内容

C# 复制多语言umbraco站点保存时的内容,c#,content-management-system,umbraco,duplication,C#,Content Management System,Umbraco,Duplication,[编辑]事实上,我已经被允许使用文档名,这使它更容易使用,但我仍然认为,如果可能的话,我会很感兴趣 我必须设置一个触发器,将内容复制到内容树上的不同分支,因为该站点将使用多种语言。有人告诉我,我不能按名称访问文档(因为它们可能会更改),我也不应该使用节点ID(不是说我会知道如何访问,过一段时间后,就很难遵循结构) 如何遍历树以其他语言在相关分支中插入新文档?有办法吗?您可以使用Document.AfterPublish事件在特定文档对象发布后捕获该对象。我将使用此事件处理程序检查节点类型别名是否

[编辑]事实上,我已经被允许使用文档名,这使它更容易使用,但我仍然认为,如果可能的话,我会很感兴趣

我必须设置一个触发器,将内容复制到内容树上的不同分支,因为该站点将使用多种语言。有人告诉我,我不能按名称访问文档(因为它们可能会更改),我也不应该使用节点ID(不是说我会知道如何访问,过一段时间后,就很难遵循结构)


如何遍历树以其他语言在相关分支中插入新文档?有办法吗?

您可以使用Document.AfterPublish事件在特定文档对象发布后捕获该对象。我将使用此事件处理程序检查节点类型别名是否为要复制的别名,然后可以调用Document.MakeNew并传递新位置的节点ID。 这意味着您不必使用特定的节点ID或文档名来捕获事件

例如:

using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic;
using umbraco.BusinessLogic;

namespace MyWebsite {
    public class MyApp : ApplicationBase {
        public MyApp()
            : base() {
            Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
        }

        void Document_AfterPublish(Document sender, PublishEventArgs e) {
            if (sender.ContentType.Alias == "DoctypeAliasOfDocumentYouWantToCopy") {
                int parentId = 0; // Change to the ID of where you want to create this document as a child.
                Document d = Document.MakeNew("Name of new document", DocumentType.GetByAlias(sender.ContentType.Alias), User.GetUser(1), parentId)
                foreach (var prop in sender.GenericProperties) {
                    d.getProperty(prop.PropertyType.Alias).Value = sender.getProperty(prop.PropertyType.Alias).Value;
                }
                d.Save();
                d.Publish(User.GetUser(1));
            }
        }
    }
}

非常感谢你。实际上,我使用Document.New对它进行了排序,因为它不需要立即发布。说这句话,你的话要简洁得多。事实上,这将有助于你完成另一部分,所以再次感谢你的朋友。