0

I have an action in my document library, but it doesn't work as it supposed.

So I have here definition of my custom action:

  <CustomAction
      Id="MyProject.Google"
      Title="Go to google"
      Location="EditControlBlock"
      RegistrationId="101"
      RegistrationType="List"
      Sequence="100"
      ControlAssembly="MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxx"
      ControlClass="MyProject.GoToGoogle">
    <UrlAction Url="www.google.com />
  </CustomAction>

Basically this action should only be only visible if it is in specified document library, but it doesn't work and it is always shown.

Here is the code:

protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                EnsureChildControls();
                _MenuItemTemp.Visible = false;
                    SPDocumentLibrary library = SPContext.Current.List as SPDocumentLibrary;
                    if (library == null)
                    {
                        return;
                    }

                    if (library.Title.equals(""))
                    {
                        _MenuItemTemp.Visible = true;
                    }
              }
            }
        }
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        _MenuItemTemp = new MenuItemTemplate
        {
            Text = "Go To Google (code)",
        };
        Controls.Add(_MenuItemTemp);
    }

I get into the code and everything, but the action menu is just always there and it doesnt matter the visible is false or true ...

And the name comes from the definition and not from code .. if this makes any sens ...

Any help?

0

If not already done, would it be possible for you to create a custom content type (even if it's just inheriting from Document), attach the content type to the list and then create the action targeting that content type ? Doing so would avoid any custom development and you can stick with XML definitions (content type, list template / instance, custom actions).

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <CustomAction Id="UserInterfaceLightUp.DocLibNewToolbar"
    RegistrationType="ContentType"
    RegistrationId="your-custom-content-type-id"
    Location="EditControlBlock"
    Sequence="100"
    Title="Go to google">
   <UrlAction Url="http://www.google.com"/>
  </CustomAction>
</Elements>
  • no, i really have to be specific on one document library, not basing on content type or whatever, so not an option, has to be with development – Shkipper Apr 4 '13 at 13:23
0

After some investigation i understood the issue, it seems that the editcontrolblock is rendered by javascript and basically server side you can't do much. And there is no way doing that.

Hope this helps someone in the future!

  • You could always disable the action if it is not in the correct list, using the EnabledScript property and write some nice javascript function that only returns true if you are actually at the specific list – Robert Lindgren May 3 '13 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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