How to disable a ribbon button when a folder is selected

I have added a new button to the SharePoint ribbon for document libraries. This all works well and the button is enabled / disabled depending on the number of items selected... fine!

I want to improve this by disabling the button when a folder is selected similar to how the standard SharePoint 'email a link' button works. Can anyone offer any advice on how to approach this? I have Googled around, but have not been able to find anything.

The code I currently have is as follows:

  <CustomAction      Id="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Action"      Location="CommandUI.Ribbon"      RegistrationType="ContentType"      RegistrationId="0x0101"      >      <CommandUIExtension>        <CommandUIDefinitions>          <CommandUIDefinition            Location="Ribbon.Documents.Copies.Controls._children">            <Button Id="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Button"                    Command="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Button.Command"                    Image16by16="/_layouts/images/Muhimbi.PDFConverter/pdf16.gif"                    Image32by32="/_layouts/images/Muhimbi.PDFConverter/pdf32.gif"                    LabelText="$Resources:ecb_title;"                    Sequence="12"                    TemplateAlias="o1" />          </CommandUIDefinition>        </CommandUIDefinitions>        <CommandUIHandlers>          <CommandUIHandler            Command="Muhimbi.SharePoint.DocumentConverter.PDF.Ribbon.Documents.Copies.Controls.ConvertAndDownload.Button.Command"            CommandAction="javascript:window.location='{SiteUrl}/_layouts/Muhimbi.PDFConverter/Convert.aspx?action=ConvertAndDownload&amp;ListId={ListId}&amp;ItemId=' + SP.ListOperation.Selection.getSelectedItems()[0].id + '&amp;Source=' + window.location"            EnabledScript="javascript:function singleEnable()            {              var items = SP.ListOperation.Selection.getSelectedItems();              var ci = CountDictionary(items);              return (ci == 1);            }            singleEnable();" />        </CommandUIHandlers>      </CommandUIExtension>    </CustomAction>  Answers: 

Use the fsObjType property:

EnabledScript="javascript:    var items = SP.ListOperation.Selection.getSelectedItems();    (items.length == 1 &amp;&amp; items[0].fsObjType == 0);"  



How To Send Email with SPUtility in Sharepoint

There is no doubt that email is a key functionality in today's enterprise. In organizations where SharePoint 2007 has also become a key collaboration platform you'll increasingly find situations where you need to send email from within the SharePoint environment. This article shows how to accomplish that, using the SPUtility class'sSendEmailmethod.

There are many scenarios where you might want to send an email notification.

In this scenario, whenever a document gets uploaded to the document library, the system first applies some business rules and logic, and then notifies users interested in that document by email. Although this is a simple scenario, it shows clearly how email is an important component of today's organizational strategies. As a SharePoint developer, that means you need a quick and easy way to send email.

Traditionally developers have used the SMTP class in ASP.NET to send email; it's quite powerful and provides fine granular control over the contents. But to use it, you need to add appropriate references and set the various properties. When your requirements are simple—such as simply sending some brief text notifications, or when email is only part of some other automated process or workflow, you may want to look at the SPUtility class'sSendEmailmethod instead. While it doesn't have the power of ASP.NET's SmtpClient class, it's much easier to use. The following example sends email usingSPUtililty.SendEmail:

private Boolean SendEmail() {   try   {     bool flag = false;     SPSecurity.RunWithElevatedPrivileges(       delegate()     {       using (SPSite site = new SPSite(         SPContext.Current.Site.ID,         SPContext.Current.Site.Zone))       {         using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))         {           flag = SPUtility.SendEmail(web, true, true,                                       "TO@example.com",                                      "Subject",                                      "This is a sample email Body");         }       }     });     return flag;   }   catch (System.Exception exp)   {     // Do some error logging     return false;   } }  

The first thing to remember is that you need to use the Microsoft.SharePoint.Utilities namespace, which contains the SPUtility class that exposes theSendEmailmethod. Note thatSendEmailoccupies only one line in the preceding code. You should also note that you may need to elevate privileges, because the current user context may not have sufficient permission to send email.

There areseveral overloads of theSendEmailmethod. The parameters for the version shown are an SPWeb object (web), followed by two Boolean parameters:AppendHtmlTags, which whentrueappends an HTML tag to the message,falseotherwise, andHtmlEncode, which whentrueencodes the message and replace characters in HTML tags with entities. The last three parameters are strings that correspond to the email'sTo,Subject, andBodyfields, respectively.

TheSendEmailmethod returns a Booleantruefor success orfalseif the send attempt failed.

As you can see, sending basic email usingSendEMailis straightforward; however, note these key considerations:

  • Attachments are not allowed.
  • By default, the message body cannot exceed 2048 characters.SendEMailwill truncate all characters beyond 2048. The workaround is to ensure that nosingle linein your message body exceeds 2048 characters. Simply add newline characters as needed to keep the lines under the 2048 character limit.
  • By default, theFromaddress is always set to the value from the Central Administration Outbound Mail Sender Address field.