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 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?

share|improve this question
add comment

2 Answers

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>
share|improve this answer
    
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
add comment
up vote 0 down vote accepted

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!

share|improve this answer
    
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
add comment

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.