Monday, December 19, 2011

Change the user profile property display ordre

On the last couple of projects, the customer wants to change the display order of the user profile properties and there is the PowerShell to do it.

To see the current user profile display order call the script like this

& '.\change userprofile display ordre.ps1' http://spsite

To change the order call the script like this

& '.\change userprofile display ordre.ps1' http://spsite nameoftheuserprofileproperty sortorder

e.g. & '.\change userprofile display ordre.ps1' http://spsite firstname 5000

Download the powershell here

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

Sunday, May 29, 2011

Ribbon Toggle button demo

I have a customer who need a toggle button in the Ribbon. Make a normal button in the Ribbon is straightforward and there is a lot of good articles out there. But there is not so many articles on the toggle button, Chris O'Brien and Wictor Wilen have some post, see the link, but not on handling server site code that call business logic to test which state the toggle button is in. My demo code is built around how to put a toggle button in a document library and test if it is on or off base on some server site business logic.

My demo code: http://cid-18d25562ce576dcc.office.live.com/self.aspx/Offentlig/SharePoint%20files/Ribbon.Demo.zip

Links:

Sunday, March 13, 2011

How to add an application server role to your SharePoint farm

To add an application sever with an application server role to your SharePoint farm run this PowerShell commands:

  1. Connect-SPConfigurationDatabase -DatabaseServer "MySqlServer" -DatabaseName "MySharePointFarmName_SharePoint_Config" -Passphrase "myPassPhrase"
  2. Install-SPHelpCollection -All
  3. Initialize-SPResourceSecurity
  4. Install-SPService
  5. Install-SPFeature -AllExistingFeatures
  6. Install-SPApplicationContent


For more infomation on this read this technet article “Add a Web or application server to the farm (SharePoint Server 2010)” - http://technet.microsoft.com/en-us/library/cc261752.aspx

Tuesday, March 1, 2011

Remove the SharePoint menu item “Edit in SharePoint Designer” in Site Action

I had a customer who wanted to remove the menu option "Edit in SharePoint Designer" in the site action. It was not simply enough to disable edit in SharePoint Designer in central administration, for it does not remove the the menu item but make it just gray.
My first thought was to make a Hidde custom action, but it turns out that many of the items in the site action can not remove by a Hidde custom action. It turns out that the menu items in the site action is hardcore in the master pagen. eg. v4.master. So we have four solutions to the problem position.
1) We can remove the rights of the logged on user.
2) In v4.master file, remove the line 147 to 157th
3) Do some JavaScript that remove the menu item
4) Make a custom control or delegate control ala:

  1. SPRibbon ribbonControl = this.Parent.Controls.Cast<Control>().First(c => (c is SPRibbon)) as SPRibbon;
  2. SPRibbonPeripheralContent ribbonPeripheralContent = ribbonControl.Controls[0] as SPRibbonPeripheralContent;
  3. SiteActions siteActions = ribbonPeripheralContent.Controls.Cast<Control>().First(c => (c is SiteActions)) as SiteActions;
  4. FeatureMenuTemplate featureMenuTemplate = siteActions.Controls[0].Controls[2] as FeatureMenuTemplate;
  5. Control editInSharePointDesigner = featureMenuTemplate.Controls.Cast<Control>().First(csd => (csd is MenuItemTemplate) && ((MenuItemTemplate)csd).Text.Equals("Edit in SharePoint Designer", StringComparison.InvariantCultureIgnoreCase));
  6. featureMenuTemplate.Controls.Remove(editInSharePointDesigner);

Sunday, January 16, 2011

Missing the open button when opening PDF files from SharePoint 2010.

By the default setting of a SharePoint 2010, a users can’t open PDF files and many other files types (see the bottom of the post for all default file type allowed to download http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.allowedinlinedownloadedmimetypes.aspx) direct from SharePoint, neither “Display PDF in browser” mode or in the download popup, where the “open” button is missing.
clip_image001

The thing is SharePoint 2010 adds an additional security header to force the file to be saved to the disk before the users can open it. To fix this the BrowserFileHandling property should be set to “permissive” http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbrowserfilehandling.aspx. This property exist both on a webapplication level http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.browserfilehandling.aspx and a on document library level http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.browserfilehandling.aspx.

To fix this on a webapplication level, by using the GUI.

  1. Open Central Administration
  2. Application Management
  3. Manage Web Applications
  4. Select the webapplication to change
  5. Click General Settings in the ribbon
  6. Scroll down to Browser File Handling and select Permissive
  7. Click on the OK button

clip_image003

To fix this with PowerShell on a webapplication level

Get-SPWebApplication http://vsitsp01 | % { $_.BrowserFileHandling = "permissive"; $_.update() }

To fix this with PowerShell on a document library level

$spweb = Get-spweb http://vsitsp01

$doclib = $spweb.Lists["Documents"]

$doclib.BrowserFileHandling

$doclib.BrowserFileHandling = "permissive"

$doclib.Update()

File types allowed to be download:

application/directx
application/envoy
application/fractals
application/internet-property-stream
application/liquidmotion
application/mac-binhex40
application/ms-infopath.xml
application/msaccess
application/msword
application/oda
application/oleobject
application/onenote
application/pics-rules
application/pkcs10
application/pkcs7-mime
application/pkcs7-signature
application/pkix-crl
application/postscript
application/rtf
application/set-payment-initiation
application/set-registration-initiation
application/streamingmedia
application/vnd.fdf
application/vnd.ms-excel
application/vnd.ms-excel.12
application/vnd.ms-excel.addin.12
application/vnd.ms-excel.binary.12
application/vnd.ms-excel.macroEnabled.12
application/vnd.ms-excel.macroEnabledTemplate.12
application/vnd.ms-excel.template.12
application/vnd.ms-office.calx
application/vnd.ms-officetheme
application/vnd.ms-pki.certstore
application/vnd.ms-pki.pko
application/vnd.ms-pki.seccat
application/vnd.ms-pki.stl
application/vnd.ms-powerpoint
application/vnd.ms-powerpoint.12
application/vnd.ms-powerpoint.addin.12
application/vnd.ms-powerpoint.macroEnabled.12
application/vnd.ms-powerpoint.presentation.12
application/vnd.ms-powerpoint.show.12
application/vnd.ms-powerpoint.show.macroEnabled.12
application/vnd.ms-powerpoint.slide.macroEnabled.12
application/vnd.ms-powerpoint.template.12
application/vnd.ms-powerpoint.template.macroEnabled.12
application/vnd.ms-project
application/vnd.ms-visio.viewer
application/vnd.ms-word.document.12
application/vnd.ms-word.document.macroEnabled.12
application/vnd.ms-word.template.12
application/vnd.ms-word.template.macroEnabled.12
application/vnd.ms-works
application/vnd.ms-xpsdocument
application/vnd.oasis.opendocument.presentation
application/vnd.oasis.opendocument.spreadsheet
application/vnd.oasis.opendocument.text
application/vnd.openxmlformats-officedocument.presentationml.slide
application/vnd.rn-realmedia
application/vnd.visio
application/vnd.visio.webdrawing
application/winhlp
application/x-bcpio
application/x-compress
application/x-cpio
application/x-csh
application/x-dvi
application/x-gtar
application/x-gzip
application/x-hdf
application/x-internet-signup
application/x-iphone
application/x-latex
application/x-miva-compiled
application/x-ms-application
application/x-ms-manifest
application/x-ms-reader
application/x-ms-vsto
application/x-ms-wmd
application/x-ms-wmz
application/x-msaccess
application/x-mscardfile
application/x-msclip
application/x-msdownload
application/x-msmediaview
application/x-msmetafile
application/x-msmoney
application/x-mspublisher
application/x-msschedule
application/x-msterminal
application/x-mswrite
application/x-netcdf
application/x-oleobject
application/x-perfmon
application/x-pkcs12
application/x-pkcs7-certificates
application/x-pkcs7-certreqresp
application/x-sh
application/x-shar
application/x-smaf
application/x-stuffit
application/x-sv4cpio
application/x-sv4crc
application/x-tar
application/x-tcl
application/x-tex
application/x-texinfo
application/x-troff
application/x-troff-man
application/x-troff-me
application/x-troff-ms
application/x-ustar
application/x-wais-source
application/x-x509-ca-cert
audio/aiff
audio/basic
audio/mid
audio/mpeg
audio/wav
audio/x-aiff
audio/x-mpegurl
audio/x-ms-wax
audio/x-ms-wma
audio/x-pn-realaudio
audio/x-pn-realaudio-plugin
audio/x-smd
drawing/x-dwf
image/bmp
image/cis-cod
image/gif
image/ief
image/jpeg
image/pjpeg
image/png
image/tiff
image/vnd.wap.wbmp
image/x-cmu-raster
image/x-cmx
image/x-icon
image/x-jg
image/x-portable-anymap
image/x-portable-bitmap
image/x-portable-graymap
image/x-portable-pixmap
image/x-rgb
image/x-xbitmap
image/x-xpixmap
image/x-xwindowdump
text/calendar
text/css
text/dlm
text/h323
text/iuls
text/plain
text/richtext
text/setext
text/tab-separated-values
text/x-ms-iqy
text/x-setext
text/x-vcard
video/mpeg
video/quicktime
video/x-ivf
video/x-la-asf
video/x-ms-wm
video/x-ms-wmp
video/x-ms-wmv
video/x-ms-wmx
video/x-ms-wvx
video/x-msvideo
video/x-sgi-movie