Question:

How to create Item of a particular Content Type from Ribbon

Mason: 5 days ago

I have a document library which has two custom types linked to it. From UI I have two buttons to add that items..

I have two simple "ribbon button" and I want to use that to create the new Item from Content Type 1 and Content Type 2...

What's the Command I must associate? Is it possile to create this by Javascript?

Another question... If I want to make some button visible ONLY in certain conditions (like I'm in folder XXX so I can create only Content Type XXX elements), how can I do?

EDIT: According with Ren Hoek's answer, I create this code:

<CustomAction
Id="AggiungiCliente"
RegistrationType="List"
RegistrationId="101"
Location="CommandUI.Ribbon">
<CommandUIExtension>
  <CommandUIDefinitions>
    <CommandUIDefinition
     Location="Ribbon.Documents.New.Controls._children">
      <Button
       Id="Ribbon.Documents.New.Controls.AggiungiCliente"
       Alt="Aggiungi Cliente Ribbon Button"
       Sequence="10"
       Image32by32="/_layouts/images/PeoplePermissions.png"
       Command="AggiungiClienteCMD"
       LabelText="Aggiungi Cliente"
       TemplateAlias="o2"/>
    </CommandUIDefinition>
  </CommandUIDefinitions>
  <CommandUIHandlers>
    <CommandUIHandler
     EnabledScript="true"
     Command="AggiungiClienteCMD"
     CommandAction="javascript:var PAGETYPE = { ItemDisplay: 4, ItemEdit: 6, ItemNew: 8 }; 
                    var baseListFormUrl = '/_layouts/listform.aspx?'; 
                    var FolderConTypeID = '0x01200016274670493a402ab037bb0597921f54'; 
                    function NewFolder() { 
                    alert('done');
                        openPopup( baseListFormUrl + 
                                   'ListId=' + escapeProperly(listid) + 
                                   '%26PageType=' + PAGETYPE.ItemNew + 
                                   '%26RoorFolder=' + escapeProperly(L_Menu_BaseUrl + '/' + folderpath) + 
                                   '%26ContentTypeId=' + FolderConTypeID  
                                   ); 
                    } 

                    function openPopup(popUpUrl) { 
                    alert('called');
                        var options = { 
                            url: popUpUrl, 
                            title: 'title', 
                            allowMaximize: false, 
                            showClose: true, 
                            width: 600, 
                            height: 500, 
                            dialogReturnValueCallback: refreshCallback 
                        } 
                    alert('invoking showModalDialog')
                        SP.UI.ModalDialog.showModalDialog(options); 
                    alert('invoked');
                    }  " />
  </CommandUIHandlers>
</CommandUIExtension>

The button appears, but no one of the "alert" is hitted. If I change my code and put only "javascript:alert("...")" it works...

Any suggestion?

Thank you very much!

Answer:
Elias: 5 days ago

best way is to call the Form for it. Here is an JS example for a Folder (call Newfolder() as Ribbon command) Maybe add a callback for refreshing:

var PAGETYPE = { ItemDisplay: 4, ItemEdit: 6, ItemNew: 8 };
var baseListFormUrl = "/_layouts/listform.aspx?";
var FolderConTypeID = "0x0120003128620337CAC849BF2F80A5409ED9C300660E3D59C0C720448BF2EC9937D387A6";
function NewFolder() {
    openPopup( baseListFormUrl +
               "ListId=" + escapeProperly(listid) +
               "&PageType=" + PAGETYPE.ItemNew +
               "&RoorFolder=" + escapeProperly(L_Menu_BaseUrl + "/" + folderpath) +
               "&ContentTypeId=" + FolderConTypeID 
               );
}

function openPopup(popUpUrl) {

    var options = {
        url: popUpUrl,
        title: 'title',
        allowMaximize: false,
        showClose: true,
        width: 600,
        height: 500,
        dialogReturnValueCallback: refreshCallback
    }
    SP.UI.ModalDialog.showModalDialog(options);
}