Custom Actions in the SharePoint Rich HTML Editor Control with a custom Pop-up dialog

April 15th, 2008 by radi a.

Me and a colleague of mine (Selvi) had to create a custom action button in the HTML Editor Control in SharePoint that performs a few bits of cool functionality. The button had to pop-up a custom aspx page with some custom options and behavior. I found documentation on this topic to be reasonably poor, so I decided to blog about what we did.

Adding the actual button isn't that hard. `The Mossman' has a nice post on this How to Add a Button to the HTML Editor Control in SharePoint. And there's also an MSDN article that describes this: How to: Add a Button to the HTML Editor Field Control.

The RTE2ToolbarExtension.xml file allows you to add extensions to the HTML editor control. You specify a new tag that points to a JavaScript file holding the button's behavior. Further below is the code that we used for our button's click event. The articles above describe the rest of the code that you need for the button to work, so there's no need for me to repeat it.

function LinkImage_OnClick(strBaseElementID, args)

{

    var HrefValue = null;

    var sFeatures=fnSetValues();

    var listName = "Media Files";

    var url = "/_layouts/CustomAppPages/AssetInsertLinkImage.aspx";

    var selectedFile = window.showModalDialog(url, selectedFile, sFeatures);

    var selectedFileValues_array = selectedFile.split("$");

    var imageUrl = selectedFileValues_array[0];

    var hrefUrl = selectedFileValues_array[1];

    var hrefTarget = selectedFileValues_array[2];

    var docEditor=RTE_GetEditorDocument(strBaseElementID);

 

    if (docEditor==null) { return; }

 

    var selection=docEditor.selection;

    var rngSelection=selection.createRange();

    rngSelection=selection.createRange();

    rngSelection.pasteHTML("<a href='"+hrefUrl+"' class='aImage' target='"+hrefTarget+"'><img alt='' src='"+imageUrl+"' /></a>");

}

 

Our goal was to return multiple values from the opened window and manipulate them in the javascript of the button. We originally tried to modify a copy of AssetImagePicker.aspx but stumbled into problems. We found an asset picker control within an <asp:Placeholder> that was hidden at runtime. We removed the control outside of the placeholder and had problems returning the values populated by the user from that specific control that was originally hidden. We couldn't figure out why so we took a different approach. The MSDN article How to: Customize the Asset Picker wasn't very helpful on this. (Anyone have any ideas?)

We created a fresh aspx page and added two some asset picker controls. We styled it to look like a typical SharePoint pop-up and with some code-behind we returned the values to the parent javascript code within the action button's click event. So here's the code we ended up with for the button:

public class AssetInsertHyperLinkImage : System.Web.UI.Page

{

    protected AssetUrlSelector assetSelectedUrl;

    protected AssetUrlSelector AssetUrlSelector1;

    protected CheckBox Checkbox1;

 

    protected override void OnInit(EventArgs e)

    {

        //Create an event handler for the button's click event 

        //The button belongs to dialog.master – OkButton

        ((DialogMaster)this.Page.Master).OkButton.Click += new EventHandler(this.btnOk_Click);

        base.OnInit(e);

 

    }

    protected void btnOk_Click(object sender, EventArgs e)

    {

        //get the values from the controls  

        string returnVariable = assetSelectedUrl.AssetUrl;

        returnVariable += "$" + AssetUrlSelector1.AssetUrl;

        returnVariable += "$" + CheckTrueFalse();

 

        String strScript = default(String);

 

        //inject some JS and the window.returnValue string  

        strScript = "<script>";

        strScript += "window.returnValue='" + returnVariable + "';";

        strScript += "window.opener=self;";

        strScript += "window.close();";

        strScript += "</script>";

        Response.Write(strScript);

    }       

 

    protected string CheckTrueFalse()

    {

        if (Checkbox1.Checked)

            return "_blank";

        else

            return "_self";

    }

}

And here is our ASPX page with some AssetUrlSelector controls :

<%@ Assembly Name="CustomApplicationPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a10a1e7c8f664a65" %>

<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Assembly Name="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Import Namespace="Microsoft.SharePoint.WebControls" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

 

<%@ Page Language="C#" Inherits="CustomApplicationPages.AssetInsertHyperLinkImage"

    MasterPageFile="/_layouts/dialog.master" %>

 

<%@ Register TagPrefix="CMS" Namespace="Microsoft.SharePoint.Publishing.WebControls"

    Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="wssuc" TagName="InputFormSection" Src="/_controltemplates/InputFormSection.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="InputFormControl" Src="/_controltemplates/InputFormControl.ascx" %>

<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderDialogBodyMainSection"

    runat="server">

<table class="ms-authoringcontrols" cellspacing="0" cellpadding="0" width="100%"

    border="0" style="padding-left: 20px">

    <tr>

        <td height="10px" class="ms-descriptiontext" colspan="2">

            <img src="/_layouts/images/blank.gif" width="1" height="10" alt="">

        </td>

    </tr>

    <tr>

        <td width="25px">

            <img src="/_layouts/images/blank.gif" width="25" height="1" alt="">

        </td>

        <td class="ms-assethyperlinkdialog-editcontrolcell">

            <wssuc:InputFormControl

            LabelText="<%$Resources:cms, asseteditimage_selectedimage_label%>"

            LabelAssociatedControlId="assetSelectedUrl" runat="server">

            <template_control>

                <CMS:AssetUrlSelector id="assetSelectedUrl"

                CssTextBox="ms-input ms-assethyperlinkdialog-longtextbox"

                MaxLength=512 DecodeUrlPath="false" runat="server"                   

                AccessibilityName="<%$Resources:cms, assetedithyperlink_selectedurl_label%>"                   

                />

                    <div>

                        <asp:RequiredFieldValidator ID="assetSelectedUrlValidator"

                        EnableClientScript="False" Display="Dynamic"

                        ControlToValidate="assetSelectedUrl"

                        Text="<%$Resources:cms, assetedithyperlink_selectedurl_required%>"

                        Runat="server" />

                    </div>

            </template_control>

            </wssuc:InputFormControl>

        </td>

    </tr>

    <tr>

        <td width="25px">

            <img src="/_layouts/images/blank.gif" width="25" height="1" alt="">

        </td>

        <td class="ms-assethyperlinkdialog-editcontrolcell">

            <wssuc:InputFormControl

            LabelText="<%$Resources:cms, assetedithyperlink_selectedurl_label%>"

                LabelAssociatedControlId="AssetUrlSelector1" runat="server">

            <template_control>

            <CMS:AssetUrlSelector id="AssetUrlSelector1"

            CssTextBox="ms-input ms-assethyperlinkdialog-longtextbox"

            MaxLength=512 DecodeUrlPath="false"

            AccessibilityName="<%$Resources:cms, assetedithyperlink_selectedurl_label%>"

            runat="server" />

                <div>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1"

                    EnableClientScript="False" Display="Dynamic"

                    ControlToValidate="AssetUrlSelector1"

                    Text="<%$Resources:cms, assetedithyperlink_selectedurl_required%>"

                    Runat="server" />

                </div>

                <BR />

                <asp:Checkbox id="Checkbox1" runat="server" />

                <asp:Label id="Label2" runat="server"  AssociatedControlID="Checkbox1"

                Text="<%$Resources:cms, assetedithyperlink_openlinkintarget_newwindow%>" />

            </template_control>

            </wssuc:InputFormControl>

        </td>

    </tr>

</table>

</asp:Content>

 

We also created a feature to deploy the .aspx and code-behind files.

I hope this helps someone.

Another live MOSS 2007 site – The AGL public facing web site

April 8th, 2008 by radi a.

My Unique World team launched this site live on Friday 04/04/2008, 10pm. I spent the last 5 weeks working on different aspects and features of the site. It was a great effort from my whole team and I'm really happy we pulled it off.

The site itself is good looking and making great use of the content management features of MOSS. It includes a product catalog, image gallery, RSS feeds, ASX tickers, email notifications to users, related documents and links web parts, great search functionality and a lot of other stuff. We made good use of content types, page layouts and master pages.

Please have a look: http://www.agl.com.au

The SharePoint Branding Tool

March 24th, 2008 by radi a.

Time to spread the word about this tool!

A colleague of mine, Douglas Leung,  has released a SharePoint Branding Tool on CodePlex: http://www.codeplex.com/BrandingTool

Great effort and worth a try! Check out the blog post here: http://sharepointsix.blogspot.com/2008/03/microsoft-sharepoint-2007-sharepoint_24.html

Burn your blog's RSS/ATOM feeds…

March 23rd, 2008 by radi a.

I am now feedburning my blog with FeedBurner. The feed URL is http://feeds.feedburner.com/IntegratingRadiWithSharepointAndDynamicsCrm so please use that if you are tracking this blog.

Why Brun?

Development Tools – My list of plugins, apps and extensions that I use every day.

March 23rd, 2008 by radi a.

From what I've seen over the past two years, some developers and workplaces use the most basic set of tools that are just enough to get the job done.  In my view, a few extra tools and gadgets can offer many short-term and long-term benefits:

  • Reductions in development time
  • Tidiness and completeness of code
  • Faster debugging capabilities
  • Elimination of tedious tasks
  • Coordination and reusability of code and components

Not only that, some tools are just cool! I'm a huge fan of things like Visual Studio add-ins, browser extensions, custom applications that do great things, custom .NET components and I even love cool keyboard shortcuts.

There's a few blog posts on dev tools and VS add-ins out there. Here's my list of the guns and weapons I use every day to get my work done. I'll try to be relevant and straight to the point.

 

Web developer browser extensions

Firebug: I still meet web developers that don't know that this tool exists. In my view this is a must-have web developer tool. It is the best add-on out there. Some SharePoint developers might argue against it because it is FF only, but the fact is it saves time. It makes CSS and HTML editing much easier live in the browser, allows for javascript debugging with breakpoints. 

IE Developer Toolbar – This is more popular than Firebug, less flexible and less powerful but often used because it is designed for IE browsers. I just love the ruler tool – Ctrl-Shift-R. IE Developer Toolbar gives a great DOM view.

Web Developer  toolbar – Firefox only. This is another favorite of mine. It offers many tweaks and quick links to things like W3C and other validation sites, resize the browser window to standard resolutions, view source and css, disable scripts, edit cookies, outline divs, show DOM information, etc. It's quite packed, give it a try.

Web Developer Helper – IE. I'm not sure if this is popular as the rest, but I think it's great. Even allows for ASP.NET debugging when running a local server. Great DOM inspector, HTTP request/response monitoring, worth a try.

 

Visual Studio Add-ins

Resharper – Resharper is a great productivity add-on and is one of my favorite. A great time-saving tool. It allows you to refactor your code and clean up untidy things. It also offers great shortcuts.

copySourceasHTML – This add-in copies the selected source code as HTML markup allowing you to paste it nicely into you blog or anywhere else.

GhostDoc – This add-in automatically generates XML comments for you. It is great when you know that someone else will review/use your code – it reminds you to put something meaningful.

SharePoint Developer Explorer – This add-in is worth following. It allows you to browse and edit SharePoint content files straight from Visual Studio.

TestDriven.NET – Unit testing add-in, allows you to run unit tests from different frameworks like Nunit, MBunit and MS Team System. Very neat and easy to use.

  

Tools and Apps

Total Commander 7.02a – My dream file manager. I was a huge user of Norton Commander. I couldn't resist using Windows Commander when it came out, and now Total Commander is just a must in my life. This offers everything you need: file comparison by content (like diff but better), efficient network transfer, great FTP, detailed file information, shortcuts, file viewer, compression tools. I love it.

Source Control – I much prefer SVN over VSS. TortoiseSVN – the windows client; VisualSVN – the visual studio add-in(which I don't use anymore). I am unfortunate that I can't use SVN at all these days.

SQL – Toad for SQL Server – Every MS SQL developer has to know Enterprise Manager and Management Studio off by heart, but Toad for SQL Server is a great alternative developer tool that makes things easier. It's free for up to 5 seats.

Notepad++ – Many people argue that the Notepad.exe that comes with Windows rocks. I beg to differ. There are tons of notepad clones out there. My favorite is Notepad++. It has nice colour coding.

U2U CAML Query Builder – I wish this was my idea, but it's not. Great tool, a must have for SP developers. Let's you test out your CAML queries.

 

Other goodies

Telerik RadControls – The best ASP.NET control suite ever! Straight from homeland Bulgaria.

Koders.com – This one is interesting, search through other people's code. Very educational. Similar to CodeKeep, it also offers a VS plugin that allows you to search from VS.

Developer Fusion VB C# converter – sometimes there's a need for converting from one language to another. I've had more success with this web site converter than with others. Great for converting big chunks of code, but hardly ever the job is 100% done. There are also potential dangers when using tools like this – the code you end up with might not be efficient or might leak.

Jetbrains Omea Reader – My favorite feed reader. This is the only tool I use to follow blogs and newsgroups and it rocks. Try it, it's free.

Microsoft Office OneNote – I'm just a fan of OneNote. I love the screen clipping tool. I love it.

HTTP Fiddler – The best HTTP debugging proxy I know.

Web Service Studio Express – A great tool for debugging web services.

Integrating Dynamics CRM with Office OneNote

March 15th, 2008 by radi a.

I was browsing around and found this great article on integrating Dynamics CRM with Office OneNote (MSDN, Jeff Cardon, Rachel Drossman). It's 4 months old but not worth missing out on.

Extending Microsoft Dynamics CRM to Office OneNote 2007

And here's a set of open-source tools that achieve it: Microsoft Dynamics Snap for Microsoft Dynamics CRM

I'm a BIG fan of OneNote, I use the screen clipping tool every day (Windows Key + S). I also love developing integration addons so I think this is a great resource. I already have great ideas on what could be created to link the two applications and exchange data.

Radi A.

SharePoint SDK has been updated for SP1

February 27th, 2008 by radi a.

For everyone that develops for SharePoint, the SDK has been updated to version 1.3 for both WSS and MOSS.

MOSS: http://www.microsoft.com/downloads/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en

WSS: http://www.microsoft.com/downloads/details.aspx?familyid=05E0DD12-8394-402B-8936-A07FE8AFAFFD&displaylang=en
 
I found a description and summary on Randall Isanhour's blog: http://blogs.msdn.com/randalli/archive/2008/02/26/sharepoint-sdk-downloads-now-live-with-sp1-updates-2-26-2008.aspx.
 
(UPDATE: While you're at it you might as well update the Visual Studio Extensions for SharePoint to v1.1: http://www.microsoft.com/downloads/details.aspx?familyid=3E1DCCCD-1CCA-433A-BB4D-97B96BF7AB63&displaylang=en)

Back to blogging…

February 27th, 2008 by radi a.

It's been a long time since I have had the chance to blog more actively due to recent events in my everyday life…

I am now a consultant with Unique World, a top SharePoint company in Australia. I will be working alongside 4 SharePoint MVP's and lots of SharePoint professionals that make up what I believe is the best SharePoint team in Australia. It's a great deal for me to join such a team and I'm looking forward to long hours developing tough SharePoint solutions.

Check out Unique World at http://www.uniqueworld.net

 

I passed my WSS MCTS exam! 70-541

January 1st, 2008 by radi a.

I'm now a happy Windows SharePoint Services Application Development MCTS!

Life has been really busy lately with work and everything else, but I still found the time to pass my WSS MCTS exam. I'm really happy as this is my first Microsoft certification. Full exam name: 70-541 TS: Microsoft Windows SharePoint Services 3.0 – Application Development

My thoughts: well out of beta, the exam had quite a lot of spelling mistakes.

for those who plan to take it, here are my recomendations:

  • Know your site definitions, develop one and deploy it.
  • Make sure you are familiar with onet.xml
  • There was a bit on installing and deploying features, so make sure you know how to do that
  • There was a few questions on deploying dll files correctly
  • 3 or 4 questions on record management
  • Site provisioning code
  • That's all I can remember for now.

Good luck for those planning to take it. Now I'll focus on getting the MOSS version done, 70-542.

 Catch.

Hosted CRM: Free information breakfast in Sydney and Brisbane

September 5th, 2007 by radi a.

For those who are interested in getting their businesses up and running with Dynamics CRM at low costs, my company is holding information breakfasts in Sydney and Brisbane. I'll be presenting some CRM customisation issues and showing demonstrations of development around CRM that our company has been undertaking, and generally talking about why we do CRM development. Steven Bennett from Microsoft Australia will be joining us to talk about CRM's roadmap.

If anyone is interested, more information could be found on www.jaythom.com.au; There is also a registration form for people wishing to attend.

The seminar is free, goes for about 1 hour and there will be free breakfast.