Wednesday, July 20, 2011

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