2

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.

3 Answers 3

1

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?

2
  • no unfortunately i haven't found a solution Commented Oct 8, 2013 at 16:24
  • 1
    OK thank you! It is too bad that MS does not fix RegistrationId="{$ListId:Lists/MyList;}" for farm solutions.
    – Yavuz
    Commented Oct 9, 2013 at 8:43
0

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

1
  • 1
    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. Commented Apr 10, 2013 at 12:56
0

You can also use GetGlobalResourceObject to get the localized string

HttpContext.GetGlobalResourceObject("name of your resource file", "resourceKey").ToString();
1
  • i think you didn't understand the question @Nizar Commented Aug 13, 2013 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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