Monday 16 February 2009

SharePoint application templates installer

Automating the process of installing SharePoint 2007 Application Templates

The application templates supplied by Microsoft are almost considered to be a standard feature of SharePoint. Anyone looking up SharePoint will come across them and inevitably want to try them out, if not deploy them to a large scale environment!

If you have not installed these templates before, its worth a go doing it manually.
The installation typically involves copying or downloading the files onto the SharePoint server, running stsadm -o addsolution -filename -title -immediate/local -allowgacdeployment. which doesnt sound like alot but when you have 20 of these, and 20 uploadable templates it gets a tad tedious.

see here for more information


There are several bat files you can download which do a mass install, but they don't do individual installs, they don't do mass removals and a couple of them are quite poorly designed..

This system:

  • optionally installs the application template core
  • presents a menu to install all & individual templates or deleting them
  • writes to a log so you can check why something might have failed
  • is commented through out for easy editing


Automation
I do these templates alot, there is usually a day put aside to configure all of the templates and test them but from now on, installing these templates where needed will be an addition to my SharePoint install routine. Automation of this task comes int he fashion of a .BAT file, its light - took 10minutes to develop, can be edited on a whim and does exactly what it supposed to so i saw no reason to get VS out and start writing an installer as such.

The purpose of this post is to tell you about how the bat file installs the application templates and how to edit the file if you wish, if your just looking to download the file - click here.


GOTO :CORE

The first thing this bat file asks when you run it is "Has APPLICATION TEMPLATE CORE been installed already?" - This is because i don't like the idea of running checks from a bat file and further more, i don't like the idea of re-installing the core every time we install a template, this will lengthen how long each install takes etc so its asked immediately and should be the first thing the user does. If a user isnt sure, i've suggested installing it anyway. once the user has selected Y, they won't see this question again until next time they run the bat file.

If the user selects "N" for No, then the application template is installed by the bat file


set fname="ApplicationTemplateCore.wsp"
set ttle="Application Template Core"
SET STS="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"
echo.
echo Adding Solution: %fname%
%STS% -o addsolution -filename %fname%
echo.
echo deploying solution: %ttle%
%STS% -o deploysolution -name %ttle% -allowgacdeployment -immediate
ECHO.
ECHO.
ECHO Copying app bin content.
ECHO.

%STS% -o copyappbincontent

ECHO.
ECHO App bin content complete.
ECHO.
ECHO.
ECHO Executing jobs.
ECHO.

%STS% -o execadmsvcjobs
ECHO.
ECHO Ready to reset IIS.
iisreset -noforce
ECHO.
ECHO CORE HAS BEEN INSTALLED
ECHO.
pause

The application template has to be installed for the templates to work, its the first thing an admin should do before installing the templates. The line marked red indicates a field which should be edited, in some instances you will need to select -local instead of -immediate.

Now our menu
:




GOTO: INSTALLALL

As it says on the tin, you can now install ALL application templates, install individual application templates or start removing them from the system. NOTE: Application template core is not removed

this is done like so:


:installall

CLS

SET STS="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"

FOR %%G IN (\templates\*.wsp) DO (
ECHO %%G start
%STS% -o addsolution -filename %%G
%STS% -o deploysolution -name %%G -allowgacdeployment -immediate
ECHO %%G end
ECHO.
ECHO.
)

ECHO Copying app bin content.
ECHO.

%STS% -o copyappbincontent

ECHO.
ECHO App bin content complete.
ECHO.
ECHO.
ECHO Executing jobs.
ECHO.

SET STS="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"

FOR %%G IN (\templates\*.stp) DO (
ECHO %%G start
%STS% -o addtemplate -filename %%G -title %%G
ECHO %%G end
ECHO.
ECHO.
)

%STS% -o execadmsvcjobs

ECHO.
ECHO Ready to reset IIS.
PAUSE

iisreset -noforce

ECHO.
ECHO Jobs complete.
ECHO.
ECHO.
ECHO Back go menu
ECHO.

PAUSE
GOTO :Start

This installs all of the application templates from within the TEMPLATES folder, it does both the .wsp files and the .stp files using a separate command. %STS% -o execadmsvcjobs is used to then run any jobs that are backed up by SharePoint (happens alot) and then its all finished off with an IIS Reset.

You'll have to monitor the bat file as it installs these templates to check that no errors occur, if an error does occur it continues on with its tasks and won't alert you. If you don't have 5 minutes to watch this process then check the log.txt file which is output and make sure everything installed successfully.

GOTO :INSTALLINDV

Another cool feature of this tool is the ability to quickly install one or more of the application templates required at a time, when you select this in the menu you'll be presented of a numbered list of all the templates and you can decide which ones to install.



Each template has its own command line call, and its own properties, which are passed into one of two method type installation processes called either :installindv or :installwsp. An example of an stp file install would be:

:add20
set fname="\templates\TimecardManagement.stp"
set ttle="Timecard Management"
GOTO :InstallIndv

:InstallIndv
ECHO.
ECHO Adding Template
SET STS="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"
%STS% -o addtemplate -filename %fname% -title %ttle%
ECHO.
ECHO Template %ttle% Added
ECHO.
ECHO.
ECHO.
ECHO Copying app bin content.
ECHO.
%STS% -o copyappbincontent
ECHO.
ECHO App bin content complete.
ECHO.
ECHO.
ECHO Executing jobs.
ECHO.
%STS% -o execadmsvcjobs
ECHO.
ECHO Job complete.
ECHO.
ECHO.
ECHO Ready to reset IIS.
iisreset -noforce
ECHO.
ECHO Back to selections
ECHO.
pause

GOTO :addselect

once this is complete, the user is presented with the menu and that template is installed. If a user attempts to install the same template again, they will get an error saying that it already exists.
adding -force to %STS% -o addtemplate -filename %fname% -title %ttle% would resolve this issue and do a clean re-installation of that template. Alternatively remove it and re-add it.

an example of a wsp (SERVER ADMIN TEMPLATE) is:


:add21
set fname="\templates\AbsenceVacationSchedule.wsp"
set ttle="Absence Request and Vacation Schedule Management "
GOTO :Installwsp

:Installwsp
CLS

SET STS="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"
echo.
echo Adding Solution: %fname%
%STS% -o addsolution -filename %fname%
echo.
echo deploying solution: %ttle%
%STS% -o deploysolution -name %ttle% -allowgacdeployment -immediate
ECHO.
ECHO.
ECHO Copying app bin content.
ECHO.

%STS% -o copyappbincontent

ECHO.
ECHO App bin content complete.
ECHO.
ECHO.
ECHO Executing jobs.
ECHO.

%STS% -o execadmsvcjobs
ECHO.
ECHO Ready to reset IIS.
iisreset -noforce
ECHO.
ECHO Back to selections
ECHO.
pause
GOTO :addselect



The main difference between the installation of a server admin template and a site admin template is simply that a site admin template just has to be added to the site template store while a server admin template has to be installed and added to the global assembly cache before it will be run and "trusted" by SharePoint.

GOTO :REMALL
The application templates can now be removed in full, again - this won't remove the application template core and DOES NOT REMOVE ALL TEMPLATES. the remove all option only removes SERVER ADMIN TEMPLATES as it uninstalls them. to remove the site admin templates:

  1. Log into your SharePoint site as the site Administrator.
  2. From the Site Actions drop-down menu in the top right,
  3. select Site Settings.
  4. Under the Galleries section, select Site templates.
  5. In the list of site templates, find the application template you wish to remove and click the Edit link.
  6. Confirm that this is the application template you wish to remove. If so, select Delete Item.
  7. Click Ok to confirm the deletion.
  8. The application template is now unavailable to SharePoint sites and has been removed from your SharePoint site template gallery.

Our bat file removes all server admin templates individually like so:

:Remallwsp
SET STS="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"
echo.

set fname="AbsenceVacationSchedule.wsp"
set ttle="Absence Request and Vacation Schedule Management "
echo retracting solution %fname%
%STS% -o retractsolution -filename %fname% -force
echo Deleting solution: %ttle%
%STS% -o deletesolution -name %ttle% -force


Now that they have all been removed. they have to be re-added and won't appear in the site templates gallery. Further to that, if the application templates are removed in full, then any sites created from these templates will no longer work.

GOTO :END

Now that you can see how the bat file works and how to edit the very basic properties of it, you can go ahead and write your own solution to performing these tasks.

Of course, you can download mines here, but i take no responsibility for it. Feel free to contact me for advice with it but please use at your own risk.

Thats all for now,

Ryan

Tuesday 10 February 2009

MOSS 2007 PDF ICON

Adding the .PDF Icon to MOSS 2007


How many SharePoint projects have you done where a week after the implementation, you get an email from the customer about the .PDF icon not existing in document libraries.

By now you probably no doubt know how to resolve the problem,

  1. Download This is the icon from Adobe.

  2. Save to TEMPLATE\IMAGES directory. (DEFAULT: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template\images)

  3. Open the file docicon.xml. (DEFAULT: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template\xml\docicon.xml)

  4. Add a new Mapping element to the ByExtension element.


    NOTE: Be sure to change pdficon_small.gif to whatever image you downloaded to represent pdf documents.

  5. Save the edited docicon.xml file.
  6. Restart IIS (iisreset /noforce).

Thats a fine fix and not too manual compared to some other fixes that are repeatedly done but recently ive been working on minimizing the amount of time i need to spend doing these tasks and writing some batch files to simplify manual fixes like this.

I have zipped up this fix so you can download it.

Download it here

the zip file contains
  • DOCICON.XML (with ammendments)
  • PDF16.Gif
  • PDFICON.BAT
the bat file does 4 things:

copy pdf16.gif "c:\program files\common files\microsoft shared\web server extensions\60\template\images\pdf16.gif" /y

this line copies the file into the images folder on the SharePoint server

rename "c:\program files\common files\microsoft shared\web server extensions\60\template\xml\docicon.xml" docicon.old

this line renames DOCICON.XML so that it can be restored if required

copy docicon.xml "c:\program files\common files\microsoft shared\web server extensions\60\template\xml\docicon.xml" /y

this line copies across the new DOCICON.XML file

iisreset /noforce

Resets IIS committing the changes

How to use

Extract the zip file to anywhere on your front end server(s) and run "pdficon.bat."


Ryan!