Wednesday, June 27, 2007

Recycle IIS Application Pool using a command line

Whenever you need to restart a Web Application, it's usually faster to recycle only the associated application pool rather than do an IISRESET.

To accomplish this using a command line, create a batch file (replace MyAppPool with the name of the application pool you want to recycle) as this:

%systemroot%\system32\iisapp.vbs /a MyAppPool /r


Command Prompt Shell Extension

To create a shell extension that opens a DOS Command Prompt on the selected folder in Windows Explorer, create and run a CmdHere.reg file:

[HKEY_CLASSES_ROOT\Directory\shell\DosHere]

@="Command &Prompt"


 

[HKEY_CLASSES_ROOT\Directory\shell\DosHere\command]

@="C:\\WINDOWS\\System32\\cmd.exe /k cd \"%1\""


 

[HKEY_CLASSES_ROOT\Drive\shell\DosHere]

@="Command &Prompt"


 

[HKEY_CLASSES_ROOT\Drive\shell\DosHere\command]

@="C:\\WINDOWS\\System32\\cmd.exe /k cd \"%1\""


 


 

How to setup a SharePoint Command Prompt

If you need to open a command prompt window to issues SharePoint administration commands such as stsadm.exe, you'll find this useful.

  1. Create a batch file C:\windows\Setspsvars.bat

@Set Path=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%

  1. Create a shortcut to C:\WINDOWS\system32\cmd.exe /k setspvars.bat

Export and import a SharePoint Site Collection between environments

When developing SharePoint solutions, is often necessary to copy a site and all subsites between environments (ex: from development to production). This requires packaging and deployment of the definitions, features and contents for all sites in the site collection.

This can be done in several ways: (1) stsadm import/export, (2) stsadm backup/restore or (3) programmatically using the SharePoint Content Migration API. Details can be found at http://technet2.microsoft.com/Office/en-us/library/16a7e571-3531-4a4e-baa7-f348a9f9d1d11033.mspx?mfr=true

This article is a walkthrough of option (1).

Supose you developed your solution http://dev.litwareinc.com/ in your development server. Your solution was based on the Publishing Site Definition and uses a custom developed feature named LitwareInc.WebParts.MyWebParts. You want to publish this solution to your development server at http://prod.litwareinc.com/ .

Export Site Collection on the Development Environment

First, you have to export the site collection definitions and content.

  1. Start a command prompt
  2. Run the following commands

    @Set Path=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%
    Stsadm.exe -o export -url http://dev.litwareinc.com -includeusersecurity -filename C:\deploy\dev.cab

  3. This will create a file C:\deploy\dev.cab that will include the site collection definitions and contents of dev.litwareinc.com

Since your site depends on a custom feature LitwareInc.WebParts.MyWebParts containing your web part, you will also need to pack this feature in your development environment, and deploy it on the production environment. If you developed your feature using Visual Studio 2005 Extensions for Windows SharePoint Services, your job is quite easy. In the bin/debug folder of your Visual Studio solution, you will find the following files and folders:

  • Solution folder
  • setup.bat
  • LitwareInc.WebParts.MyWebParts.dll
  • LitwareInc.WebParts.MyWebParts.pdb
  • LitwareInc.WebParts.MyWebParts.wsp

Just copy these files and folders to C:\deploy. You can now copy this folder to the production server and start deploying your solution on that environment.

Import Site Collection on the Production Environment

First, you need to create a blank site definition on which you will deploy your solution. Go to Central Administration, create a new Web Application http://prod.litwareinc.com/ and then create a new site collection using the Blank Site template.

  1. Start a command prompt
  2. Run the following command

    @Set Path=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%
    setup.bat /siteurl http://prod.litwareinc.com
    Stsadm.exe -i export -url http://prod.litwareinc.com -includeusersecurity -filename C:\deploy\dev.cab

Your're done. Navigate to http://prod.litwareinc.com/ (don't forget to add an entry in your hosts file or DNS server) and check your SharePoint site collection deployed in your production server.