locked
Context menu for List Items RRS feed

  • Question

  • Hi All,

    Is there any way to create context menu or toolbar item only for a particular custom list?. I've created a menu item as a feature using the following code,

    <CustomAction
        RegistrationId="100"
        RegistrationType="List"
          Location="EditControlBlock"
          Sequence="1000"
          Title="Add/View Notes">
        <UrlAction Url="/_layouts/notesnnoteshistory/AddNewNotes.aspx?item={ItemId}&amp;list={ListId}&amp;url={SiteUrl}"/>
      </CustomAction>

    But this menu item is available to all the custom lists. Is there any way to restrict this menu item to be appeared only on a particular custom list?

    Please help me,


    thank you,

    Arun


    Sunday, October 28, 2007 2:52 PM

Answers

  • I believe you need to create a custom list definition so it is assigned a particular RedistrationId, this way you will be able to create a menu item available to only a particular custom list.

    Sunday, October 28, 2007 3:56 PM
  • Arun,

     

    Although I did not quite understand the multi-value lookup field... it seems that if you need to include a custom field type definition in your setup (more coding) to fullfill the lookup requirement. Then, create the custom list definition including a reference to the custom type.
    Monday, October 29, 2007 6:08 PM

All replies

  • I believe you need to create a custom list definition so it is assigned a particular RedistrationId, this way you will be able to create a menu item available to only a particular custom list.

    Sunday, October 28, 2007 3:56 PM
  • Hi  fedroponce,
    thank you for the reply.
    I was thinking of the same thing. But my problem is I have a multi-value lookup field that needs to be implemented in the custom list definition. That is creating problem. Still I am working on that, if i can solve this, custom list definition will do the job for me.

    Regards,

    Arun

    Monday, October 29, 2007 5:10 AM
  • Arun,

     

    Although I did not quite understand the multi-value lookup field... it seems that if you need to include a custom field type definition in your setup (more coding) to fullfill the lookup requirement. Then, create the custom list definition including a reference to the custom type.
    Monday, October 29, 2007 6:08 PM
  • Hi  fedroponce,

    The problem is while defining a look up field it needs the "list" attribute which holds the GUID of the list to which the lookup has to be made. The sharepoint built in lists gets ID only after it gets created. So its not possible to provide correct guid in the CAML definition while defining the field. I tried by putting "/lists/<listname>" for the "list" attribute, but don't know why it gave an unexpected error.
    I found a work around for this, and i dont know its the best way or not, but it is doing my job now. Since I am creating the list definition as a feature, I could create a feature event receiver that addes my custom field to the list. I used the SP OM for retrieving the connected lists GUID and created the CAML during runtime. Then I used SPFieldCollection's AddAsXML to add a field to my list from this CAML string.

    thank you,

    Arun
     OptimusBT
    Wednesday, October 31, 2007 9:31 AM
  • Arun,

     

    You are right... if the list is going to be created by a feature it seems that coding an event receiver is the right way to do it.

     

    Your solution looks interesting... would you mind to post some code from your event receiver... it might come handy.

     

    Thanks.

     

    Wednesday, October 31, 2007 5:03 PM
  • Hi fedroponce,

     

    here is the code that I used for adding a lookup field to my list. Please note, this is not an optimised code, just a demonstration.

     

    //The Method for adding the field

    public void CreateMemList(SPWeb myWeb)

    {

     

    myWeb.AllowUnsafeUpdates = true;

    Guid myListId = myWeb.Lists.Add("GroupMembers", "Stores the grouping info", SPListTemplateType.GenericList);

    myWeb.Update();

    SPList myGroupList = myWeb.Lists["GroupMembers"];

    SPList myContacts = myWeb.Lists["Contacts"];

    string strCaml = "<Field Mult=\"TRUE\" UnlimitedLengthInDocumentLibrary=\"TRUE\" Group=\"OptimusBTContacts\" Type=\"LookupMulti\" List=\"{" + myContacts.ID + "}\" ShowField=\"Title\" Name=\"GroupMembers\" DisplayName=\"GroupMembers\" Sortable=\"FALSE\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"GroupMembers\" />";

    //Response.Write(strCaml);

    myGroupList.Fields.AddFieldAsXml(strCaml, true, SPAddFieldOptions.Default);

    }

    }

     

     

    //The Feature eventhandler

    public override void FeatureActivated(SPFeatureReceiverProperties properties)

    {

    SPWeb currWeb = null;

    using (SPSite mySite = properties.Feature.Parent as SPSite)

    {

    if (mySite != null)

    {

    currWeb = mySite.RootWeb;

    }

    else

    {

    currWeb = properties.Feature.Parent as SPWeb;

    }

    CreateMemList(currWeb);

    }

    }

    Thursday, November 15, 2007 8:11 AM