Sunday, November 6, 2011

Playing with SharePoint Rich Text Editor (RTE)

At my current project we needed to add a text highlight function button to the Rich Text Editors (RTE) ribbon, so when the user click on the button a selected text in the RTE, is wrapped with a predetermined HTML tag, indicating the text has been highlighted. Like <span css=”highlight”>the selected text</span>

The thing we need is:

1) The button in the ribbon, only showed when we are in the context of the RTE

2) The JavaScript snippet the will interact with the RTE

3) A feature the adds the ribbon button and the JavaScript to the page

The button is added to the style group like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
   Id="Ribbon.Demo.HighlightText"
   Location="CommandUI.Ribbon"
   Title="Insert Tooltips">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.EditingTools.CPEditTab.Styles.Controls._children">
          <Button
           Id="Ribbon.Demo.HighlightText.Button"
           Sequence="12"
           LabelText="High light text"
           Alt="High light text"
           TemplateAlias="o1"
           Image32by32="/_layouts/RTE.Demo/images/highlight32.png"
           Command="Ribbon.Demo.HighlightText.Command"
           ToolTipTitle="High light text"
      />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="Ribbon.Demo.HighlightText.Command"
         CommandAction="javascript:HighLightText();"
         EnabledScript="true" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

The JavaScript snippet looks like this:

function HighLightText() {
    var rng = RTE.Cursor.get_range().$3_0;
    var selectedText = RTE.Cursor.s_range.get_text();
    RTE.Cursor.get_range().deleteContent();
    var d = rng.ownerDocument;
    var a = d.createElement("span");
    a.innerHTML = selectedText;
    a.setAttribute("class", "highlight");
    SP.UI.UIUtility.insertAfter(a, rng);
}

Download the full project here

Saturday, September 17, 2011

Events for Danes at the SharePoint Conference

There are a lot of events at this year's SharePoint Conference, so in order to keep up, I've collected a list of events that are of interest to Danes.

Monday 3 October

20:00-00:00 - The RED Party presented by AvePoint
- http://www.avepoint.com/spc2011/the_red_party/
Heat Ultra Lounge (Anaheim GardenWalk,321 Katella Avenue, Anaheim) (http://www.heatultraloungeoc.com/)

20:30 – Danskerarrangement
- http://www.linkedin.com/groups/Danskerarrangement-mandag-3-oktober-kl-3830839.S.68372719

Tuesday 4 October

2000-1200 - Disneyland® Park Private Party for SharePoint Conference 2011
- http://www.mssharepointconference.com/pages/activitiespage.aspx#disney

Wednesday 5 October

17:00-19:30 - SP&TheCity Drinks&Networking (danske kvindelige deltagere)
- http://www.linkedin.com/groups/Ogs%C3%A5-i-%C3%A5r-inviterer-vi-3830839.S.50541142?qid=5df809d6-1fde-4738-8d1c-1ec08f13d637
Anabella Hotel, Tangerine Grill & Patio

20:00 - SharePint @ the SharePoint Conference 2011 in Anaheim, CA
- http://www.andrewconnell.com/blog/archive/2011/08/22.aspx
ESPNZone (http://www.espnzone.com/anaheim/)

19:30-1:00 - OktoberFiesta!
- http://events.r20.constantcontact.com/register/event?oeidk=a07e4rymr7ffc255c6b&llr=b4mprxfab
Tortilla Jo's Restaurant, Downtown Disney, Anaheim, CA

Friday, July 29, 2011

Visual Studio 2010 SharePoint Power Tools

The Visual Studio 2010 SharePoint Power Tools is a set of templates and extensions that provides additional functionality to SharePoint developers who use the SharePoint developer tools in Visual Studio 2010. Below is the list of features included in the current release of the power tools.

http://visualstudiogallery.msdn.microsoft.com/8e602a8c-6714-4549-9e95-f3700344b0d9/

Wednesday, July 20, 2011

How to create send to connection with PowerShell?

Send to connection is used in many seniors, so being able to deploy them through PowerShell is a must and it is in this way you do it:

First the XML configuration file, SendTos tag can be added multiple times if you have several applications. Under the SendTos tag is SendTo which is the connection itself. A send to consist of an Action, which can Copy, Move, or Link. Explanation which is the description for sending the link. Official filename is the name or title of sending the link. OfficialFileUrl is the URL of the site as the document to be sent, N.B. Remember that the content organizer feature must be enabled on the site. ShowOnSendToMenu is whether it should be shown in the document context menu.

  1. <SendTos WebApplicationUrl="http://win-l2sfc3oetnn/">
  2. <SendTo>
  3. <Action>Move</Action>
  4. <Explanation>Move the document to 'a' site collection</Explanation>
  5. <OfficialFileName>Move to 'a'</OfficialFileName>
  6. <OfficialFileUrl>/docid/a/_vti_bin/officialfile.asmx</OfficialFileUrl>
  7. <ShowOnSendToMenu>false</ShowOnSendToMenu>
  8. </SendTo>
  9. </SendTos>

The second part, is the PowerShell, where I loops thought the to sends tags and grab the web application. Then I test whether the connection already exists, if not I create it by adding a Microsoft.SharePoint.SPOfficialFileHost to OfficialFileHosts collection located on the web application.

  1. [xml]$SendTos = gc $pwd\sendto.xml
  2.  
  3. $SendTos.SendTos | % {
  4. $webapp = Get-SPWebApplication $_.WebApplicationUrl.TrimEnd("/")
  5.  
  6. $_.SendTo | % {
  7. $SendTo = $_
  8.  
  9. $officialFileHostTemp = $webapp.OfficialFileHosts | ? {
  10. $_.OfficialFileName -eq $SendTo.OfficialFileName
  11. }
  12.  
  13. if($officialFileHostTemp -eq $null)
  14. {
  15. [Microsoft.SharePoint.SPOfficialFileHost] $officialFileHost = New-Object "Microsoft.SharePoint.SPOfficialFileHost"
  16. $officialFileHost.Action = [Enum]::Parse([Microsoft.SharePoint.SPOfficialFileAction], $SendTo.Action)
  17. $officialFileHost.Explanation = $SendTo.Explanation
  18. $officialFileHost.OfficialFileName = $SendTo.OfficialFileName
  19. $officialFileHost.OfficialFileUrl = $url+$SendTo.OfficialFileUrl
  20. $officialFileHost.ShowOnSendToMenu = [bool]::Parse($SendTo.ShowOnSendToMenu)
  21. $webapp.OfficialFileHosts.Add($officialFileHost)
  22. $webapp.Update()
  23. }
  24. $officialFileHostTemp = $null
  25. }
  26. }

Change the PowerShell UI Culture

At one of my projects I’m using the new and greater multi language options in SharePoint 2010 and with ASP.Net resources it is really easy to create site in different languages. When I create a site e.g. in Danish the content type display name is translated into Danish, as expected, but when I start my SharePoint managed shell it is running in English context and if I have some PowerShell code which is dependent on language resources, then it will ask in English, but when my site is created in Danish, it may give some weird errors. The solution to this is to set PowerShell CurrentUICulture to be as the site you work with like this.

  1. #Ensure the PowerShell process is running the same culture as SPWeb is created with
  2. $web = Get-SPWeb "http://win-l2sfc3oetnn"
  3. [int]$lcid = $web.Language
  4. $culture = new-object "System.Globalization.CultureInfo" $lcid
  5. [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture