One of the things I needed to do in order to get my Site Directory set up and working properly was to be able to modify the view that controls which columns appear when creating a new site collection. The way SharePoint determines which columns to use is via a special view that is created when you set up a site directory. The name of the view is "Site Creation Categories" and you can see it here: "http://[portal]/SiteDirectory/SitesList/Capture.aspx". If you want to control which columns appear when creating a new site then simply edit this view and add or remove those columns. Of course, I'm writing a batch file to make all these modifications so I needed to be able to do this via STSADM.
As you might imagine there is no built-in command to edit views so I had to create my own which I called gl-updatelistview. I started out pretty simple - just made it so that you could control the visibility of columns but then I decided that I'd try to add more so as to make it potentially more useful. In the end you can modify just about everything via this command that you could otherwise modify via the browser (there are some things I left out such as the Totals column settings). I thought about maybe taking it further and creating the ability to create a view as well but at present I don't have that need so I only did the update (it wouldn't be a stretch to create a createlistview command if needed).
The piece of functionality that messed me up the most was the setting of the View Style. It's easy enough to set the style but if you want to change the setting back to the "Default" setting there's simply no way to do this via the API. What I ended up having to do was use reflection to get the internal XmlDocument object where all the settings are stored and then manually remove the <ViewStyle /> node. Ugly I know but its the only way I could find to do it. The code can be seen below:The syntax of the command can be seen below:
C:\>stsadm -help gl-updatelistview stsadm -o gl-updatelistview Updates a list view. Parameters: -url <list view URL> [-visiblefieldorder <comma separated list of internal field names>] [-viewname <view name>] [-mobileview <true | false>] [-defaultmobileview <true | false>] [-rowlimit <number of items to display>] [-paged <true | false>] [-scope <default | recursive | recursiveall | filesonly>] [-style <view style>] [-sort <use the following format where the field name is the internal field name (leave blank to clear): "field1=asc|desc,field2=asc|desc">] [-filter <CAML XML (leave blank to clear)> [-group <use the following format where the field name is the internal field name (leave blank to clear): "field1=asc|desc,field2=asc|desc">] [-collapsegroups <true | false>] [-grouplimit <number of groups to display per page>] [-makedefault <true | false>] [-hidden <true | false>]Here's an example of how to update a view using all of the above parameters:
Note that when specifying the CAML for the filter make sure that you wrap it in quotes and use tick marks for quotes in the XML otherwise you'll get command line errors.stsadm -o gl-updatelistview -url "http://intranet/SiteDirectory/SitesList/Capture.aspx" -visiblefieldorder "DivisionMulti,RegionMulti" -viewname "Site Creation Categories" -mobileview false -defaultmobileview false -rowlimit 100 -paged true -scope recursive -style "Basic Table" -sort "DivisionMulti=asc,RegionMulti=asc" -filter "<Where><Or><Eq><FieldRef Name='DivisionMulti' /><Value Type='Text'>Operations</Value></Eq><Eq><FieldRef Name='DivisionMulti' /><Value Type='Text'>Human Resources</Value></Eq></Or></Where>" -group "DivisionMulti=asc" -collapsegroups false -grouplimit 100 -makedefault true -hidden false