Frage

I have a SP2010 site with 3 variations. EN , FR , DE. EN is my master variation where the content editors create their page. SP then automagically copies the page to the FR and DE variations.

So far so good.

I'm wondering if it is possible to look up a page his "counterpart" in the other variations.

Example: I'm on the page http://mydomain.com/en/pages/introduction.aspx Can I find the french counterpart in the FR variation? So http://mydomain.com/fr/pages/introduction.aspx ?

Simply replacing the 'en' with 'fr' in the url will not do since the 'pages' library might be translated as well.

Thanks, W0ut

War es hilfreich?

Lösung

I think the simplest method is to get the list using PublishingPage.VariationPageUrls.

It gets a StringCollection object of URLs that point to Variation peer PublishingPage objects associated with this PublishingPage object.

So in your code, it would be something like..

if (PublishingPage.IsPublishingPage(SPContext.Current.ListItem))
            {
                PublishingPage page = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);
                StringCollection peerUrls = page.VariationPageUrls;
                foreach (var peerUrl in peerUrls)
                {

                }
            }

Apart from that if you want to get all variation labels, use

ReadOnlyCollection<VariationLabel> spawnedLabels = Variations.Current.UserAccessibleLabels;

Once you have the label you can access its members like locale, display name, title etc. Check VariationLabel Members

Once you have variation label, you can even call yourPublishingPage.GetVariation(variationLabel) method to get exact URL of current page's counterpart (given the variable label).

I hope this connects all dots and you get everything you want with properly expose APIs.

Andere Tipps

First a disclaimer: the below notes are a pure recollection from memory of a project I was involved back in 2008.

Assuming http://mydomain.com/en/pages/introduction.aspx is your publishing master variation page. This page contains a hidden text field named "PublishingVariationGroupID". This field contains a GUID which can be used to locate all matching pages. How? Read on!

The hidden "Relationships List" contains two important fields, not visible if you hit the default view http://mydomain.com/Relationships%20List/

  • ObjectID == contains a relative path of each publishing variation page as "Hyperlink or Picture" field
  • GroupID == contains a GUID value, as "Single line of text", of the "PublishingVariationGroupID" field

So, as a first step, create a new view on the "Relationships List" list which includes "ObjectID" and group it by "GroupID".

This will give you a grouped view containing all publishing pages relative URL paths. By expanding a group you'll see all matching variation pages for a particular publishing page.

To leverage this information by code you need to:

  • Get the current publishing page (e.g. by using SPContext.Current.ListItem)
  • Get the hidden field "PublishingVariationGroupID" (e.g. by using SPListItem.Fields["PublishingVariationGroupID"])
  • Now get a handle of the hidden "Relationships List" list and construct a SPQuery to retrieve all items which contain the value of SPListItem.Fields["PublishingVariationGroupID"] of the "Relationships List" list "GroupID" field.
  • All now returned items are pointing to a publishing variation page URL which can be used to work with the page itself.

Hope that sheds some more light into the inner workings of SharePoint variations.

Although the french for pages is "pages", in most other languages it will be different, so the pages libraries will be called "Paginas", "Seiten", etc.

If you want to get to the "welcome" page for each site, you can just strip the URL down to the variation label; e.g. http://mydomain.com/fr/.

Programmatically, you could get the name of the pages library for the PublishingWeb. You can also get the word for "Pages" from the resources. But beware - there is, at the time of writing, an error in the Spanish core resource file - use the osrvcore version instead (i.e. $Resources:osrvcore,List_Pages_UrlName).

Use the PublishingPage.GetVariation Method. Get the peer Variation PublishingPage object that belongs to this PublishingPage object for the specified Label.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top