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