Click here to Skip to main content
15,893,814 members
Articles / Programming Languages / XML

Custom SharePoint STSADM Commands

Rate me:
Please Sign up or sign in to vote.
4.90/5 (9 votes)
22 May 2007CPOL4 min read 67.1K   588   27  
Writing custom commands for the stsadm.exe administration tool in SharePoint.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.StsAdmin;

namespace HSG.Sharepoint.STSADM.Commands
{
    /// <summary>
    /// Displays information about all Timer Job Definitions in a site collection.
    /// </summary>
    public class GetJobInfos : ISPStsadmCommand
    {
        public string GetHelpMessage(string command)
        {
            return "\r\n\r\nDisplays Information about the all Timer Jobs in the given site collection\r\n\r\nParemeters:\r\n\t-url <url of site collection>";
        }

        public int Run(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
        {
            output = string.Empty;

            #region Check Arguments
            if (!keyValues.ContainsKey("url") || keyValues["url"].Length == 0)
            {
                output = "Please specify a url of a site collection.";
                output += GetHelpMessage(command);
                return 0;
            }
            #endregion

            string siteCollectionUrl = keyValues["url"];

            using (SPSite site = new SPSite(siteCollectionUrl))
            {
                foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                {
                    if (job != null)
                    {
                        output += Helper.GetJobInformation(job);
                        output += "\r\n";
                    }
                }
            }

            return 1;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
I'm a .net developer for Windows Forms, Web Apps, Office and SharePoint.

Comments and Discussions