Tridion 如何在C#NET中获取出版物WebDAV URL

Tridion 如何在C#NET中获取出版物WebDAV URL,tridion,Tridion,我正在尝试获取我的出版物WebDAV url,下面是我正在尝试的逻辑,我成功地获取了页面和组件的webdavurl,但是很难获取出版物url public static string getPublicationWebDav(string partialWebdavURL, Package package, Engine engine) { string webDav = string.Empty; string pubURI = string.Empty; if (!string.IsNull

我正在尝试获取我的出版物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。

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