Using the codesample of Todd Baginski's post of creating a custom activity to email, I modified the code to create a doclib using two variables that an user enters in SPD. These two variables are the url of the site and the title of the document library.
I replaced the code of Todd with this chunk :
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
namespace CreateDocumentLibrary
{ public partial class Doclib: SequenceActivity
{
private EventLog _eventLog;
public static DependencyProperty UrlProperty =
DependencyProperty.Register("Url", typeof(string), typeof(Doclib));
public static DependencyProperty ListNameProperty =
DependencyProperty.Register("ListName", typeof(string), typeof(Doclib));
[ValidationOption(ValidationOption.Required)]
public string Url
{ get
{ return (string)base.GetValue(UrlProperty);
}
set
{ base.SetValue(UrlProperty, value);
}
}
[ValidationOption(ValidationOption.Required)]
public string ListName
{ get
{ return (string)base.GetValue(ListNameProperty);
}
set
{ base.SetValue(ListNameProperty, value);
}
}
protected override ActivityExecutionStatus
Execute(ActivityExecutionContext executionContext)
{ //Set up the Event Logging object
_eventLog = new EventLog("Workflow"); _eventLog.Source = "SharePoint Workflow";
try
{ //Send the email
CreateList();
}
finally
{ //Dispose of the Event Logging object
_eventLog.Dispose();
}
//Indicate the activity has closed
return ActivityExecutionStatus.Closed;
}
private void CreateList()
{ try
{ SPSite site = new SPSite(Url);
SPWeb rootweb = site.OpenWeb();
SPListCollection lists = rootweb.Lists;
SPListTemplateType listTemplateType = new SPListTemplateType();
listTemplateType = SPListTemplateType.DocumentLibrary;
lists.Add(ListName, "", listTemplateType);
_eventLog.WriteEntry("Worklow succes: List
created at: " + rootweb.Title.ToString());
}
catch (System.Exception Ex)
{ //Log exceptions in the Event Log
_eventLog.WriteEntry("Workflow Error :" +
Ex.Message.ToString(), EventLogEntryType.Information); }
}
public Doclib()
{ InitializeComponent();
}
}
}
And the XML to publish this code in SPD in the WSS.ACTIONS looks like:
<Action Name="Create Document Library"
ClassName="CreateDocumentLibrary.Doclib"
Assembly="CreateDocumentLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=54d1a6fdf526a294"
AppliesTo="all"
Category="Sample">
<RuleDesigner Sentence="Create document library %1 on %2.">
<FieldBind Field="Url" Text="Link to site" DesignerType="TextArea" Id="1"/>
<FieldBind Field="ListName" Text="Name of the doclib" Id="2" DesignerType="TextArea"/>
</RuleDesigner>
<Parameters>
<Parameter Name="Url" Type="System.String, mscorlib" Direction="In" />
<Parameter Name="ListName" Type="System.String, mscorlib" Direction="In" />
</Parameters>
</Action>
</Actions>
So if you want use this code, follow all the steps that are described in the post of Todd and replace his code and xml with mine and you could be a happy man! ;)