Cannot get latest SPListItem attributes such as ForwardLinks in a page that was propagated using variations

Consider the following scenario:

As a site collection administrator, you use object model to get SPListItem.ForwardLinks in a page that has been propagated in a target site with variations sytem. The page version is at least 1.1.

As a result, you are not able to retrieve SPListItem.ForwardLinks attribute from the current minor version, it returns properties from the last published version (in this scenario 1.0)

Although you are a site collection administrator, you cannot get SPListItem.ForwardLinks properties from the current minor version. This is probably the same behavior with others attributes such as BackwardLinks, but this works fine with title attribute (and probably many others).

To workaround this, you must run your code with elevated privileges to use application pool account. You can find a sample below:

 

void CheckSPListItemPropertiesAsApppoolAccount(string weburl, string listname)
{
    Result.Text = "";
    Result.Text += "<br/>Running as application pool account";

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite(weburl))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists[listname];
                Result.Text += "<br/><br/>Number of items: " + list.ItemCount.ToString();

                foreach (SPListItem item in list.Items)
                {
                    try
                    {
                        Result.Text += "<br/><br/>Item: " + item.Title;
                        foreach (SPLink link in item.ForwardLinks)
                        {
                            Result.Text += "<br/>URL: " + link.Url;
                        }
                    }
                    catch (Exception e)
                    {
                        Result.Text += "<br/>" + e.Message;
                        Result.Text += "<br/>" + e.StackTrace;
                    }
                }
            }
        }
    });
}