Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
    
This question is probably off-topic for StackOverflow, but would be very welcome on the SharePoint.StackExchange.com site. –  SPDoctor Nov 11 '11 at 12:37
    
Do you want to do this by code or via the SharePoint UI? –  Sig Weber Nov 11 '11 at 13:16
    
I've seen on Stefan's post on Customising Variations there's a hidden control that you can extend to link directly to the other versions of a page. I'm keen to know if we can access this information elsewhere for other purposes. –  Zhaph - Ben Duguid Feb 4 '12 at 12:43
add comment

migrated from stackoverflow.com Nov 11 '11 at 12:53

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 8 down vote accepted
+50

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.

share|improve this answer
    
Excellent! I've totally forgotten that the OM provides a method for it. But then, it's been many years that I've been messing with variations. –  Sig Weber Feb 9 '12 at 21:39
    
Many thanks Ashish, that looks ideal :) –  Zhaph - Ben Duguid Feb 10 '12 at 11:19
add comment

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.

share|improve this answer
    
Many thanks Sig, I'll see what I can get working ;) –  Zhaph - Ben Duguid Feb 4 '12 at 19:35
    
This solved my problem. Because I had been having something strange. I had implemented @Ashish Patel logic, but for certain pages it didn't work. Akward? Yes Indeed! I checked Relationships List and I created a new view where I grouped pages by GroupGuid. And it happened that for some records the Label (I included this also on the view) was an empty GUID??? How is this possible?? Anyway your answer solved my problem –  MIlena Jan 18 at 16:53
add comment

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).

share|improve this answer
1  
You can get the localized name of the pages directory using PublishingWeb.PagesListName –  Anders Rask Feb 4 '12 at 22:50
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.