<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SharePointBlog.nl &#187; variations</title>
	<atom:link href="http://www.sharepointblog.nl/tag/variations/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sharepointblog.nl</link>
	<description>Michiel Lankamp</description>
	<lastBuildDate>Wed, 26 May 2010 09:37:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>VariationSettings Import/Export Utility on Codeplex</title>
		<link>http://www.sharepointblog.nl/2007/10/14/variationsettings-importexport-utility-on-codeplex/</link>
		<comments>http://www.sharepointblog.nl/2007/10/14/variationsettings-importexport-utility-on-codeplex/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 23:27:53 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MOSS]]></category>
		<category><![CDATA[codeplex]]></category>
		<category><![CDATA[variations]]></category>

		<guid isPermaLink="false">http://www.sharepointblog.nl/?p=25</guid>
		<description><![CDATA[I have completed my application for import/export of variations, I have uploaded everything to codeplex so have a look there: http://www.codeplex.com/variationsettings A neat little command utility that lets you do three things: - Export the current variationsettings and labels to xml - Import the variationsettings and label from xml - EXPERIMENTAL: create the variation hierachies [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.sharepointblog.nl%2F2007%2F10%2F14%2Fvariationsettings-importexport-utility-on-codeplex%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.sharepointblog.nl%2F2007%2F10%2F14%2Fvariationsettings-importexport-utility-on-codeplex%2F&amp;source=m_lampje&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>I have completed my application for import/export of variations, I have uploaded everything to codeplex so have a look there:</p>
<p><a href="http://www.codeplex.com/variationsettings">http://www.codeplex.com/variationsettings</a></p>
<p>A neat little command utility that lets you do three things:<br />
- Export the current variationsettings and labels to xml<br />
- Import the variationsettings and label from xml<br />
- EXPERIMENTAL: create the variation hierachies</p>
<p>Background<br />
This application was created to extend our daily buildprocess for a public internet website</p>
<p>More Information<br />
Check out Michiel Lankamp&#8217;s blog entry: <a href="http://www.sharepointblog.nl/2007/10/14/variationsettings-importexport-utility-on-codeplex/">http://www.sharepointblog.nl/2007/10/14/variationsettings-importexport-utility-on-codeplex/</a></p>
<p>Want the code?<br />
Get it from <a href="http://www.codeplex.com/variationsettings/SourceControl/ListDownloadableCommits.aspx">http://www.codeplex.com/variationsettings/SourceControl/ListDownloadableCommits.aspx</a></p>
<p>Want the build?<br />
Get it from <a href="http://www.codeplex.com/variationsettings/Release/ProjectReleases.aspx">http://www.codeplex.com/variationsettings/Release/ProjectReleases.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sharepointblog.nl/2007/10/14/variationsettings-importexport-utility-on-codeplex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable variations programmatically</title>
		<link>http://www.sharepointblog.nl/2007/10/14/enable-variations-programmatically/</link>
		<comments>http://www.sharepointblog.nl/2007/10/14/enable-variations-programmatically/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 22:07:35 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MOSS]]></category>
		<category><![CDATA[variations]]></category>
		<category><![CDATA[webclient]]></category>

		<guid isPermaLink="false">http://www.sharepointblog.nl/?p=15</guid>
		<description><![CDATA[Last week I was trying to enable variations using a feature in SharePoint, but I soon realized that I had a problem because Microsoft decided to make all the variation-class internal. So that shouldn&#8217;t be a problem, why not use reflection. That didn&#8217;t work either, so back to the good old Lutz Roeder&#8217;s Reflector to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.sharepointblog.nl%2F2007%2F10%2F14%2Fenable-variations-programmatically%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.sharepointblog.nl%2F2007%2F10%2F14%2Fenable-variations-programmatically%2F&amp;source=m_lampje&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Last week I was trying to enable variations using a feature in SharePoint, but I soon realized that I had a problem because Microsoft decided to make all the variation-class internal. So that shouldn&#8217;t be a problem, why not use reflection. That didn&#8217;t work either, so back to the good old <a href="http://www.aisto.com/roeder/dotnet/" target="_blank">Lutz Roeder&#8217;s Reflector</a> to see what&#8217;s going on. I soon found out that variations are dependent on 2 hidden lists (VariationSettings, VariationLabels), both lists can be found using the AllProperties of the root web:<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="kwrd">using</span> (<span class="typ">SPSite</span> site = <span class="kwrd">new</span> <span class="typ">SPSite</span>(<span class="str">"http://localhost"</span>))
{
    <span class="kwrd">using</span> (<span class="typ">SPWeb</span> rootweb = site.RootWeb)
    {
        <span class="kwrd">string</span> _VarRelationshipsListId = rootweb.AllProperties[<span class="str">"_VarRelationshipsListId"</span>].ToString();
        <span class="kwrd">string</span> _VarLabelsListId = rootweb.AllProperties[<span class="str">"_VarLabelsListId"</span>].ToString();

        <span class="typ">SPList</span> VariationLabels = rootweb.Lists[<span class="kwrd">new</span> Guid(_VarLabelsListId)];
        <span class="typ">SPList</span> VariationSettings = rootweb.Lists[<span class="kwrd">new</span> Guid(_VarRelationshipsListId)];
    }
}</pre>
<p>The variationlabels list contains a listitem for each variation that is available on the site, just add a new listitem to the list (make sure there is only one listitem that has the field &#8220;Is Source&#8221; set to true):<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">SPListItem variation = VariationLabels.Items.Add();
variation[<span class="str">"Hierarchy Is Created"</span>] = <span class="kwrd">false</span>;
variation[SPBuiltInFieldId.Title] = <span class="str">"EN"</span>;
variation[<span class="str">"Description"</span>] = <span class="str">"English"</span>;
variation[<span class="str">"Flag Control Display Name"</span>] = <span class="str">"English"</span>;
variation[<span class="str">"Language"</span>] = <span class="str">"en—US"</span>;
variation[<span class="str">"Locale"</span>] = 1033;
variation[<span class="str">"Hierarchy Creation Mode"</span>] = <span class="str">"Publishing Sites and All Pages"</span>;
variation[<span class="str">"Is Source"</span>] = <span class="kwrd">false</span>;
variation.Update();</pre>
<p>The variationsettings are a little bit different, the settings are saved to the propertybag of the rootfolder of the list:<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">VariationSettings.RootFolder.Properties[<span class="str">"SourceVarRootWebTemplatePropertyName"</span>] = “sitetemplate#0”;
VariationSettings.RootFolder.Properties[<span class="str">"EnableAutoSpawnPropertyName"</span>] = <span class="kwrd">true</span>;
VariationSettings.RootFolder.Properties[<span class="str">"AutoSpawnStopAfterDeletePropertyName"</span>] = <span class="kwrd">true</span>;
VariationSettings.RootFolder.Properties[<span class="str">"UpdateWebPartsPropertyName"</span>] = <span class="kwrd">true</span>;
VariationSettings.RootFolder.Properties[<span class="str">"CopyResourcesPropertyName"</span>] = <span class="kwrd">true</span>;
VariationSettings.RootFolder.Properties[<span class="str">"SendNotificationEmailPropertyName"</span>] = <span class="kwrd">true</span>;
VariationSettings.Update();</pre>
<p>These settings where easy, but then came the hard part, how do I create the hierarchies since all logic is internally scoped. Then I had a brainwave, why not try the good old webclient&#8230; It works:<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="kwrd">using</span> (WebClient webClient = <span class="kwrd">new</span> WebClient())
{
    <span class="kwrd">byte</span>[] response;
    webClient.UseDefaultCredentials = <span class="kwrd">true</span>;
    response = webClient.DownloadData(input.Url + <span class="str">"/_Layouts/VariationLabels.aspx"</span>);

    <span class="rem">//get viewstate and requestdigest from page</span>
    <span class="kwrd">string</span> viewstate = ExtractHiddenValue(<span class="str">"__VIEWSTATE"</span>, Encoding.ASCII.GetString(response));
    <span class="kwrd">string</span> requestdigest = ExtractHiddenValue(<span class="str">"__REQUESTDIGEST"</span>, Encoding.ASCII.GetString(response));

    <span class="rem">//format the postdata</span>
    <span class="kwrd">string</span> postData =
        String.Format(<span class="str">"__VIEWSTATE={0}&amp;__REQUESTDIGEST={1}&amp;__EVENTTARGET={2}&amp;__EVENTARGUMENT={3}"</span>,
                      viewstate, requestdigest,
                      <span class="str">"ctl00$PlaceHolderMain$ctl00$RptControls$variationLabelsCreateHierarchiesToolBarButton"</span>,
                      <span class="str">""</span>);

    <span class="rem">//send postdata to server</span>
    webClient.Headers.Add(<span class="str">"Content-Type"</span>, <span class="str">"application/x-www-form-urlencoded"</span>);
    webClient.UploadData(input.Url + <span class="str">"/_Layouts/VariationLabels.aspx"</span>, <span class="str">"POST"</span>,
                         Encoding.ASCII.GetBytes(postData));
}</pre>
<p>Now I was finally able to create the hierachies in my build-script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sharepointblog.nl/2007/10/14/enable-variations-programmatically/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
