【问题标题】:How to get Publication WebDAV URL in C# .NET如何在 C# .NET 中获取发布 WebDAV URL
【发布时间】:2011-10-11 08:35:04
【问题描述】:

我正在尝试获取我的发布 WebDAV url,下面是我正在尝试的逻辑,我成功获取了页面和组件的 webdavurl,但是很难获取发布 url。

public static string getPublicationWebDav(string partialWebdavURL, Package package, Engine engine)
{
string webDav = string.Empty;
string pubURI = string.Empty;
if (!string.IsNullOrEmpty(partialWebdavURL))
{
_log.Info("partialWebdavURL" + partialWebdavURL);

RepositoryLocalObject repLocalObject = null;

if (repLocalObject == null)
{
Item pubItem = package.GetByType(ContentType.Publication);

repLocalObject = (Publication)engine.GetObject(pubItem.GetAsSource().GetValue("ID"));
}
webDav = repLocalObject.WebDavUrl + partialWebdavURL;
}
_log.Info("webDav" + webDav);
return webDav;
}

这一行给我错误

repLocalObject = (Publication)engine.GetObject(pubItem.GetAsSource().GetValue("ID"));

但是,当我试图让页面对象正常工作时,下面的代码工作正常。

if (package.GetByType(ContentType.Page) != null)
{
Item pageItem = package.GetByType(ContentType.Page);
//_log.Info("pageItem" + pageItem);
repLocalObject = (Page)engine.GetObject(pageItem.GetAsSource().GetValue("ID"));
pubURI = package.GetValue("Page.Publication.ID");
}
else
{
Item component = package.GetByType(ContentType.Component);
repLocalObject = (Component)engine.GetObject(component.GetAsSource().GetValue("ID"));
pubURI = package.GetValue("Component.Publication.ID");
}

我的目标是获取 Publication webdavURL。

【问题讨论】:

    标签: tridion


    【解决方案1】:

    在 tridion 论坛中长时间搜索后,我找到了以下解决方案。感谢努诺!!

    // 首先我们必须找到我们正在渲染的当前对象

    RepositoryLocalObject context;
        if (p.GetByName(Package.PageName) != null)
            context = e.GetObject(p.GetByName(Package.PageName)) as RepositoryLocalObject;
        else
            context = e.GetObject(p.GetByName(Package.ComponentName)) as RepositoryLocalObject;
    
    Repository contextPublication = context.ContextRepository;
    string webdavUrl = contextPublication.WebDavUrl;
    

    请注意,以下代码将在 2011 年有效,但在 2009 年无效(存储库的 WebDavUrl 未公开)。在 2009 年,我得到了 contextPublication.RootFolder.WebDavUrl。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多