Monday, November 26, 2007

Enabling the language switch in SharePoint

Today someone at work pointed out that there was a switch control in SharePoint that allows users to easily switch between the different languages a page is available in. I hadn't heard of this already, so if you haven't either, now you've got no more excuses to say you don't!

Now what exactly does it do? Quite easy... If variations are enabled and there's a version of a certain page available in a different language, a switch will show up to easily switch between the different versions of the page. If your page only exists in English for example, the switch control won't show up.

But most importantly... How do you enable it? Well, that's easy too. All you need to do is follow some simple steps:

- Go to the ...\12\TEMPLATE\CONTROLTEMPLATES folder and open the VariationsLabelMenu.ascx file.

- Look for the line that's commented out. Remove the comment tags to enable the control. Here's the line you should comment out:

<cms:VariationsLabelEcbMenu id ="varlabelmenu1" DataSourceID="LabelMenuDataSource" DisplayText="<%$Resources:cms,VariationLabelMenuTitle%>" IsCallbackMode="true" runat="server" />

- Now go to the Master Page you want to include the control in and make sure that it has the following tag at the top:

<%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>

If this tag is on your Master Page and you've commented out the control, then the switch control should be showing right beside the links in the upper right corner of the Master Page. Now you can use this control and put it where ever you want to. If you want, you can also use it like this:

<PublishingVariations:VariationsLabelMenu id="labelmenu1" runat="server"/>

Easy as that!

Thursday, November 8, 2007

Cannot update. Database or object is read-only.

In Access 2007 you have a great feature that can copy data from or to a SharePoint list, but the error messages could have been better...

While copying a whole bunch of data, I got the following error:

Cannot update. Database or object is read-only.

Very vague... Looking at the record that caused the error (another great feature of the new Access, it shows which records couldn't be copied) I saw nothing strange. When googling for the error message, I even found a page telling that this was a known issue with a Hotfix for it, so I first thought that there was no way for me to solve this error quickly. When taking another look at the record though, I noticed a multiline field I overlooked. At the end of this field, there was a strange sign (a question mark in a little square), which was obviously causing the error...

So, long story short, if you ever run into this error, just check your data (all of it, don't be like me...) and try copying field by field to determine the field with the "illegal" character.

Wednesday, November 7, 2007

Files uploaded programmatically don't work for all users

Files uploaded programmatically don't work for all users

Today I encountered a problem when uploading images in a feature. Everything seemed to work fine, the images (used in my master page) appeared nicely where they should be, but then I logged in as another user and it just showed me the typical red x's. I noticed that the images were still checked out to the Administrator, so I checked them in programmatically and... still nothing. At first I thought they were not visible due to some kind of permissions problem, but the real solution was that you also need to publish a major version of the file. So if you ever upload files through code, do not forget these lines:

//Upload the new file.
SPFile addedFile = destinationFolder.Files.Add(fileName, fileToAdd.Open(FileMode.Open));

//Check in the newly created file and then publish a major version of it.
addedFile.CheckIn("File checked in by activating FodCustomLayout feature.");
addedFile.Publish("File published by activating FodCustomLayout feature.");