Associating a custom policy file with a content type is powerful, but administrative users will not be able to change the policy unless they can associate a different file with the content type at runtime. Two approaches come to mind. You could provide a custom user interface for entering the acceptable bid amount and estimated hours and then generate an XML file, or you could create a command-line tool.
Working with XML files via command-line utilities is a lot easier than developing a UI, especially if the schema is changing frequently during development. In addition, you might like to enable a machine-driven process or a script to modify the policy rather than require human interaction. Fortunately, the wise and benevolent SharePoint gods made it quite easy to extend the stsadm command-line tool with your own custom commands. Listing 11-13 shows a custom stsadm extension for setting the proposal management policy that will be applied to new or existing proposals based on your project proposal content type.
using System; using System.IO; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.StsAdmin; using ProSharePoint2007; namespace ProposalManager.Admin { /// <summary> /// Implements a custom STSADM command to display the proposal management /// policy specification for a given site. /// </summary> public class GetProposalPolicy : ISPStsadmCommand { #region ISPStsadmCommand Members string ISPStsadmCommand.GetHelpMessage(string command) { string msg = "Displays the current Proposal Management policy."; return msg + " " + "-url <url> the url of the site to process"; } int ISPStsadmCommand.Run(string command, System.Collections.Specialized.StringDictionary keyValues, out string output) { int result = 1; const string ProposalContentTypeName = "Project Proposal"; try { // validate the arguments if (keyValues["url"] == null) throw new ApplicationException("No url supplied."); // open the website using (SPSite site = new SPSite(keyValues["url"])){ using (SPWeb web = site.OpenWeb()){ // load the Project Proposal content type ContentType ctProjectProposal = new ContentType(); if (ctProjectProposal.Create(web, ProposalContentTypeName) == null) { throw new ApplicationException( string.Format( "Failed to locate Content Type "{0}'", ProposalContentTypeName)); } // load the policy ProposalManagementPolicy policy = ProposalManagementPolicy.FromContentType( ctProjectProposal); // convert to text and return result output = policy.ToString(); result = 0; } }} catch (Exception x) { output = x.ToString(); } return result; } #endregion } } |
To deploy the command, you simply install the assembly into the Global Assembly Cache and create a command definition file named stsadmcommands.proposalmanager.xml in the 12CONFIG folder.
<?xml version="1.0" encoding="utf-8" ?> <commands> <command name="setproposalpolicy" class="ProposalManager.Admin.SetProposalPolicy, ProposalManager.Admin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3c6b2ee283bb579c"/> <command name="getproposalpolicy" class="ProposalManager.Admin.GetProposalPolicy, ProposalManager.Admin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3c6b2ee283bb579c"/> </commands>
Figure 11-12 shows the new command being executed.
18.223.33.157