Sunday, July 28, 2013

Popup for SharePoint 2010 Lookups

Normally SharePoint 2010 Lookups open in a new tab.  So if you want to open it as a popup, it is really simple. Add fallowing script to your SharePoint page.

<script type="text/javascript">
var winIsDlg = 0;
(function () {
 var e, q = window.location.search.substring(1), r = /([^&=]+)=([^&]+)/g;
 while (e = r.exec(q))
    if(decodeURIComponent(e[1])=="IsDlg" && decodeURIComponent(e[2]) == "1")
    {winIsDlg=1;}
})();

$(document).ready(function(){
 if(winIsDlg==1)
 {
    $("td[id='SPFieldLookup'] a").each(
      function(){
       this.href="javascript:OpenPopUpPage('" + this.href + "')";
      });
 }
});
</script>

Tuesday, June 11, 2013

Extension Method to Send HTML Emails in SharePoint

/// <summary>
/// </summary>
/// Sends an email to the selected users
/// <param name="web">The web.</param>
/// <param name="from">From.</param>
/// <param name="to">To.</param>
/// <param name="cc">The cc.</param>
/// <param name="bcc">The BCC.</param>
/// <param name="subject">The subject.</param>
/// <param name="body">The body.</param>
/// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
public void SendEmail(SPWeb web, string from, string to, string cc, string bcc, string subject, string body, bool isHtml)
{
    if (!string.IsNullOrEmpty(to))
    {
        var headers = new StringDictionary{
            {"to", to},
            {"subject", subject},
            {"content-type", isHtml ? "text/html" : "text/plain"}
        };

        if (!string.IsNullOrEmpty(from))
        {
            headers.Add("from", from);
        }

        if (!string.IsNullOrEmpty(cc))
        {
            headers.Add("cc", cc);
        }
        if (!string.IsNullOrEmpty(bcc))
        {
            headers.Add("bcc", bcc);
        }

        SPUtility.SendEmail(web, headers, body);
    }
}