Monday, 9 January 2012

Exporting and importing all my site collections using PowerShell

Here is the PowerShell script that I used for exporting (backuping) and importing (restoring) all "my site" site collections. This script could be used as an alternative to STSADM mergecontentdbs command which I found a little bit inflexible. I used this script for moving my sites to a different web application.

Exporting my sites:
$mysitesurl = "http://portal/my/personal/*"
$backuppath = "c:\MySitesBackup\"
$webapp = "http://portal"
Get-SPSite -WebApplication $webapp -Limit ALL | where { $_.Url -like $mysitesurl } | ForEach-Object{ $path = $backuppath + $_.Url.Substring($_.Url.LastIndexOf("/")+1); Backup-SPSite -Identity $_.Url -Path $path -Verbose }



Importing my sites:
$mysitesurl = "http://portal/my/personal/*"
$backuppath = "c:\MySitesBackup\"
$webapp = "http://portal"
Get-SPSite -WebApplication $webapp | where { $_.Url -like $mysitesurl } | ForEach-Object{ $path = $backuppath + $_.Url.Substring($_.Url.LastIndexOf("/")+1); Backup-SPSite -Identity $_.Url -Path $path -Verbose -Force }


Sunday, 16 October 2011

Displaying Project Server fields in SharePoint site

Recently I was working on the SharePoint project and the client wanted to display and edit some Project Server fields on Project Server SharePoint site. You can do this using OOTB Project Fields webpart which comes with Project Web Access (PWA) add-in. But there's a catch. This webpart can be used only on some specific pages which support Project Server context. If you place the webpart on a page which doesn't support the context, you'll get "The webpart cannot be displayed in this context" error message. To overcome this limitation I develop webpart which works on every page on  the Project Server site.

And here is the screenshot:


The SharePoint solution is available for download here.


Friday, 22 July 2011

SharePoint 2010 warm up console app

I'm sure you could  find a lot of PowerShell scripts around which do the same. This simple console app just makes it much easier. It warms up all site within Sharepoint farm and all you need to do is to schedule it in Task Scheduler. Or you can run it manually, of course.

Requirements:
  • User account running this application must have at least read permission in all sites. If not, the site won't be warmed up.

Sample app output

The application is available for download here.

Sunday, 15 May 2011

Turning on Detailed Error Messages in SharePoint 2010 - SharePoint ignoring value in the CustomErrors tag issue

This is not new but I found the situation in which the following recommended procedure won't work.
  1. On the web server, navigate to the site directory (probably something like: C:\Inetpub\wwwroot\wss\VirtualDirectories\80 )
  2. Open the web.config file in Notepad
  3. Search for the safemode node with the word "CallStack" and change the CallStack status to true
    <SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
  4. Search for the CustomErrors node and set the mode to Off
    <customErrors mode="Off" />
  5. Save and close.
So what to do if you update web.config and you still can't see detailed error messages?


The problem is that you're probably running into the error in the _layouts subfolder. In that case the solution is easy:


  1. On the web server, navigate to the c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS folder
  2. Open the web.config file in Notepad
  3. Search for the CustomErrors node and set the mode to Off
    <customErrors mode="Off" />
  4. Save and close.
Hope this helps,

David



Force to open InfoPath forms in the browser

If you were working with browser-based InfoPath forms in SharePoint 2007/2010, you might run into a really annoying issue. In some situations the forms are opening in the client application, this usually happens when:
  1. You have InfoPath application installed on your computer.
  2. You're opening the form from within the task (e.g. task in Approval workflow) - see next picture

To overcome this problem, I created a simple SharePoint solution which forces SharePoint to open the form inside browser. It uses JQuery framework and it's packaged into the standard SharePoint solution. All you need to do is to install the solution and activate Open InfoPath forms in browser feature under Site Collection Features.

You can download the solution here.

Hope this helps,

David

Tuesday, 10 May 2011

Prompt when opening PDF in SharePoint

This is a really annoying problem. You can see on the next screenshot what I'm talking about.


Why SharePoint just can't download the file and open it? It's the PDF file so you can't edit it anyway.

To be honest, we can't blame SharePoint in this situation. The SharePoint starts to treat PDF files this way after you install PDF iFilter and modify docIcon.xml file in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML folder.

In this article by Microsoft you can find that when installing PDF iFilter you need to add <Mapping Key="pdf" Value="pdf16.gif" /> entry to docIcon.xml file. The entry should be <Mapping Key="pdf" Value="pdf16.gif" OpenControl="" />. After you update the entry and restart IIS using iisreset, everything should be OK:




Hope this helps,

David

Monday, 9 May 2011

Publishing site with multiple master pages

OK, let's be honest, this is not a common scenario. Usually you can live only with one master page and it should be enough for everyone. But from time to time you run to crazy clients which want to rape the SharePoint and turn it upside down.

You'll need another master page if you want to create page/pages inside SharePoint site which are a quite different from your current master page. It could be a different page structure or look and feel.

To implement multiple master pages you need to:
  1. Install DavidK.SP.Publishing.wsp solution
  2. Create a custom master page
  3. Create a custom page layout which will reference your custom master page. The easiest way to do this is to copy BlankWebPartPage.aspx, then edit the page layout and change the Inherits attribute to:

    DavidK.SP.Publishing.PageLayoutWithCustomMasterPage,DavidK.SP.Publishing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a9645fc7d9034814

    Also, add the MasterPageFile attribute which should contain the path to custom master page. In my case it is the following string:

    MasterPageFile="/_catalogs/masterpage/DavidK_custom.master"


Page layout with a custom master page
That's all, just check in the master page and page layout, approve it and create a new publishing page from this page layout.

Hope this helps,

David