C# 创建与已发布项的关系

C# 创建与已发布项的关系,c#,umbraco7,eventhandler,C#,Umbraco7,Eventhandler,我正在创建一个eventHandler,用于在多语言网站的内容中创建项的副本。 我试图找出,如何检查该项目是否已经有关系。 有人能帮忙吗 我的代码 public class CopyDocumentToRelatedOnPublish : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, Application

我正在创建一个eventHandler,用于在多语言网站的内容中创建项的副本。 我试图找出,如何检查该项目是否已经有关系。 有人能帮忙吗

我的代码

public class CopyDocumentToRelatedOnPublish : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase    umbracoApplication, ApplicationContext applicationContext)
    {
        base.ApplicationStarted(umbracoApplication, applicationContext);
        //subscribe to the afterpublish events
        Umbraco.Core.Services.ContentService.Published += ContentService_Published;
    }

    void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<IContent> e)
    {
        var rs = ApplicationContext.Current.Services.RelationService;
        var cs = ApplicationContext.Current.Services.ContentService;

        foreach (IContent item in e.PublishedEntities)
        {

            //here is the problem!
            if ()
            {
                cs.Copy(item, item.Id, true);
            }
        }
    }
}
公共类CopyDocumentToRelatedOnPublish:ApplicationEventHandler
{
受保护的覆盖无效应用程序已启动(UmbracoApplicationBase umbracoApplication、ApplicationContext ApplicationContext)
{
base.ApplicationStarted(umbraco应用程序、applicationContext);
//订阅afterpublish事件
Umbraco.Core.Services.ContentService.Published+=ContentService\u Published;
}
已发布无效内容服务(Umbraco.Core.Publishing.ippublishingstrategy发送方,Umbraco.Core.Events.PublishEventArgs e)
{
var rs=ApplicationContext.Current.Services.RelationService;
var cs=ApplicationContext.Current.Services.ContentService;
foreach(e.publisheddenties中的i内容项)
{
//问题就在这里!
如果()
{
cs.副本(项目,项目Id,真实);
}
}
}
}

您可以使用RelationService上的方法
AreRelated
检查现有关系