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 work in a farm environment and i want to add a CustomAction in a specific SPList. The list is created programmatically, so i cannot know the ID. For that i tried to register the action with RegistrationId="{$ListId:Lists/MyList;}".

<CustomAction
    Id="MyCustomAction"
    Location="CommandUI.Ribbon.ListView"
    RegistrationType="List"
    RegistrationId="{$ListId:Lists/MyList;}">

    ...

</CustomAction>

As i read and figure out, there is a bug in farm environment and i cannot register the action this way. I decided to add the action programmatically

SPUserCustomAction action = splist.UserCustomActions.Add();
action.Location = "CommandUI.Ribbon.ListView";
action.CommandUIExtension = @"
    <CommandUIExtension xmlns='http://schemas.microsoft.com/sharepoint/'>
        <CommandUIDefinitions>
            <CommandUIDefinition Location='Ribbon.ListItem.Actions.Controls._children'>
                <Button
                    Id='MyCustomActionButton'
                    Command='MyCustomActionCommand'
                    Image16by16='/_images/info_16x16.png'
                    Image32by32='/_images/info_32x32.png'
                    LabelText='$Resources:MyResources,Title;'
                    TemplateAlias='o1'
                    Sequence='25'
                />
            </CommandUIDefinition>
        </CommandUIDefinitions>

        ...

    </CommandUIExtension>
";
action.Update();

Now action is registered successfully but the problem is with the button label text. How it can be localized through code?

EDIT

There is the property CommandUIExtensionResource in SPUserCustomAction, that i suppose i could use, but i cannot find any example. I have use TitleResource in SPList, but the same usage in this case does not work.

share|improve this question

3 Answers 3

I have the same problem. It seems to be that there is no way to add programmatically a localizable custom action.

Declarative custom actions are localizable. But to target them to a specific list in a declarative way we need to make templates of the custom list. I did not found a way to build a template for external lists.

So it seems to be impossible to add localizable custom actions to a specific external list.

Just because RegistrationId="{$ListId:Lists/MyList;}" does not work in farm solutions.

Do you have solved your problem?

share|improve this answer
    
no unfortunately i haven't found a solution –  pbaris Oct 8 '13 at 16:24
    
OK thank you! It is too bad that MS does not fix RegistrationId="{$ListId:Lists/MyList;}" for farm solutions. –  Yavuz Oct 9 '13 at 8:43

you can use MS SPUtility class to read resource files:

SPUtility.GetLocalizedString(
string.Format("$Resources:{0}", resourceKey), 
"name of your resource file", 
(uint)SPContext.Current.Web.Locale.LCID
);

Hope it helps,

Andrew

share|improve this answer
    
If you are suggesting to localize the string to the current locale before creating the action, that would mean that the action will use a constant text. That also means that the action would not support MUI usage. –  SPArchaeologist Apr 10 '13 at 12:56

You can also use GetGlobalResourceObject to get the localized string

HttpContext.GetGlobalResourceObject("name of your resource file", "resourceKey").ToString();
share|improve this answer
    
i think you didn't understand the question @Nizar –  pbaris Aug 13 '13 at 13:40

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.