I am trying to find current PageWorkId / WorkId. I need this to populate custom data (control) on the page. The data is stored separately from EpiServer database.
I have tried following code but None of this is returning me Current WorkId.
1)
var currentPage = HttpContext.Current.CurrentHandler as PageBase;
Hi,
I am trying to find current PageWorkId / WorkId.
I need this to populate custom data (control) on the page. The data is stored separately from EpiServer database.
I have tried following code but None of this is returning me Current WorkId.
1)
var currentPage = HttpContext.Current.CurrentHandler as PageBase;
if (currentPage != null)
{
_pageId = currentPage.CurrentPage.PageLink.ID;
_versionId = currentPage.CurrentPage.PageLink.WorkID; //CurrentPage.WorkPageID;
}
2)
PageData page = DataFactory.Instance.GetDefaultPageData(CurrentPage.PageLink, CurrentPage.PageTypeID); // page's current PageLink have WorkId = 0
3)
PageReference pageRef1 = CurrentPage.PageLink;
4)
PageReference pageRef2 = CurrentPageLink;
The following code works, but only for latest version.
PageReference pageRef = MyDataHelper.GetCurrentPublishedVersion(CurrentPage); // **
if (pageRef != null)
{
_pageId = pageRef.ID;
_versionId = pageRef.WorkID;
}
** - GetCurrentPublishedVersion is a custom method which iterate through all versions and return published version.