Zobrazujú sa príspevky s označením SharePoint. Zobraziť všetky príspevky
Zobrazujú sa príspevky s označením SharePoint. Zobraziť všetky príspevky

streda 7. októbra 2009

PowerShell and SharePoint API

PowerShell and SharePoint API is really powerfull combination which can help us to automatize administration and development tasks. SharePoint exposes .NET API which can be typically called from some .NET programming language such as C#. Using this approach we have to write code, compile it and than run. SharePoint API can be also used from PowerShell, this approach removes the step of compilation. Only write a script and run it.

Following PowerShell script demonstrates using of SharePoint API from PowerShell. Script is intended to collectively set the force checkout property of document libraries (Shared Documents) in all webs of the site collection on true.


   1:  #################################################################################

   2:  #

   3:  #  Set-RequireCheckOut

   4:  #  Sets ForceCheckout on document libraries Shared Documents on site collection

   5:  #

   6:  #################################################################################

   7:   

   8:  param

   9:  (

  10:      [string] $siteUrl

  11:  )

  12:   

  13:  [void][Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

  14:   

  15:  $site = New-Object Microsoft.SharePoint.SPSite $siteUrl

  16:   

  17:  foreach ($web in $site.AllWebs)

  18:  {

  19:      foreach ($list in $web.Lists)

  20:      {

  21:          if ($list.Title -eq "Shared Documents")

  22:          {

  23:              $list.ForceCheckout = $True

  24:              $list.Update()

  25:          } 

  26:      }

  27:  }

Manning - Windows PowerShell In ActionMS Press - Inside Microsoft Windows SharePoint Services Version 3

pondelok 21. septembra 2009

Visual Studio Macros

I think Visual Studio macros is interesting feature which is not often used. Using macros you can automate repetitive tasks and increase your development productivity. You can create your own macros using Macro Exlorer (View - Other Windows - Macro Explorer).

My sample shows macro for generating new GUID in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, which is common task at SharePoint development when writing some stuff in CAML:


   1:  Imports System

   2:  Imports EnvDTE

   3:  Imports EnvDTE80

   4:  Imports EnvDTE90

   5:   

   6:  Public Module SharePointMacros

   7:      Sub CreateNewGuid()

   8:          Dim doc As Document = DTE.ActiveDocument

   9:          Dim textDoc As TextDocument = CType(doc.Object("TextDocument"), TextDocument)

  10:   

  11:          textDoc.StartPoint.CreateEditPoint()

  12:          textDoc.Selection.Insert("{" + Guid.NewGuid.ToString() + "}")

  13:      End Sub

  14:  End Module


To associate your macro with keyboard shortcut go to Tools - Options - Environment - Keyboard, find macro in command list, press shortcut (CTRL+N, CTRL+G) and assign it.


Setting VS keyboard shortcut

When you press the shortcut in code editor, macro will be run and new GUID will be inserted on the cursor position.


APress - Writting Add-Ins for Visual Stutio .NETWiley - Developing Visual Studio .NET Macros and Add-Ins