2

我正在尝试获取我的发布 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");
}

我的目标是获得发布 webdavURL。

4

1 回答 1

4

在 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。

于 2011-10-12T03:46:40.890 回答