CreateSubSite.cs

namespace INETA.Pakistan.SPDCustomActions
{
    public class CreateSubSite : SequenceActivity
    {

        #region __Context
        public WorkflowContext __Context
        {
            get { return (WorkflowContext)GetValue(__ContextProperty); }
            set { SetValue(__ContextProperty, value); }
        }

        public static DependencyProperty __ContextProperty = 
           DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(CreateSubSite));
        #endregion
        #region UrlName
        public string UrlName
        {
            get { return (string)GetValue(UrlNameProperty); }
            set { SetValue(UrlNameProperty, value); }
        }

        public static DependencyProperty UrlNameProperty = 
           DependencyProperty.Register("UrlName", typeof(string), typeof(CreateSubSite));
        #endregion
        #region SiteTemplateTitle
        public string SiteTemplateTitle
        {
            get { return (string)GetValue(SiteTemplateTitleProperty); }
            set { SetValue(SiteTemplateTitleProperty, value); }
        }

        public static readonly DependencyProperty SiteTemplateTitleProperty = 
           DependencyProperty.Register("SiteTemplateTitle", typeof(string), typeof(CreateSubSite));
        #endregion
        #region SiteTitle
        public string SiteTitle
        {
            get { return (string)GetValue(SiteTitleProperty); }
            set { SetValue(SiteTitleProperty, value); }
        }

        public static DependencyProperty SiteTitleProperty = 
           DependencyProperty.Register("SiteTitle", typeof(string), typeof(CreateSubSite));
        #endregion
        #region SiteDescription
        public string SiteDescription
        {
            get { return (string)GetValue(SiteDescriptionProperty); }
            set { SetValue(SiteDescriptionProperty, value); }
        }

        public static DependencyProperty SiteDescriptionProperty = 
           DependencyProperty.Register("SiteDescription", typeof(string), typeof(CreateSubSite));
        #endregion
        #region UseUniquePermissions
        public string UseUniquePermissions
        {
            get { return (string)GetValue(UseUniquePermissionsProperty); }
            set { SetValue(UseUniquePermissionsProperty, value); }
        }

        public static DependencyProperty UseUniquePermissionsProperty = 
           DependencyProperty.Register("UseUniquePermissions", typeof(string), typeof(CreateSubSite));
        #endregion
        #region NewSiteUrl
        public string NewSiteUrl
        {
            get { return (string)GetValue(NewSiteUrlProperty); }
            set { SetValue(NewSiteUrlProperty, value); }
        }

        public static DependencyProperty NewSiteUrlProperty = 
           DependencyProperty.Register("NewSiteUrl", typeof(string), typeof(CreateSubSite));
        #endregion

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            uint LocaleID = 1033;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    using (SPSite sourceSite = new SPSite(this.__Context.Web.Site.ID))
                    {
                        using (SPWeb currentWeb = sourceSite.AllWebs[this.__Context.Web.ID])
                        {
                            string siteTemplateName = null;
                            currentWeb.AllowUnsafeUpdates = true;

                            SPWebTemplateCollection templates = 
                                                      currentWeb.GetAvailableWebTemplates(LocaleID);
                            foreach (SPWebTemplate wt in templates)
                            {
                                if (wt.Title == SiteTemplateTitle)
                                {
                                    siteTemplateName = wt.Name;
                                    break;
                                }
                            }

                            if (siteTemplateName == null)
                                throw new Exception("Web Template not found.");

                            SPWeb newWeb = currentWeb.Webs.Add( UrlName, 
                                                         SiteTitle, 
                                                         SiteDescription, 
                                                         LocaleID, 
                                                         siteTemplateName, 
                                                         Boolean.Parse(UseUniquePermissions), 
                                                         false);

                            this.NewSiteUrl = newWeb.Url;
                            currentWeb.AllowUnsafeUpdates = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("CreateSubSite", ex.ToString());
                    throw ex;
                }
            });
            return base.Execute(executionContext);
        }
    }
}



CreateSubSite.actions

<WorkflowInfo>
  <Actions Sequential="then" Parallel="and">
    <Action Name="Create SubSite" 
  ClassName="INETA.Pakistan.SPDCustomActions.CreateSubSite" 
  Assembly="INETA.Pakistan.SPDCustomActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ecb989474e4a71da" 
  AppliesTo="all" 
  Category="INETA Pakistan Site Provision Actions">
      <RuleDesigner Sentence="Create sub-site at URL %1 using Template %2: 
                                                  Use %3 for title and %4 for description; 
                                                  %5 Unique Permissions; Store Url in %6">
        <FieldBind Field="UrlName" DesignerType="TextArea" Id="1"/>
        <FieldBind Field="SiteTemplateTitle" DesignerType="TextArea" Id="2"/>
        <FieldBind Field="SiteTitle" DesignerType="TextArea" Id="3"/>
        <FieldBind Field="SiteDescription" DesignerType="TextArea" Id="4"/>
        <FieldBind Field="UseUniquePermissions" DesignerType="Dropdown" Text="choose"  Id="5">
          <Option Name="Use" Value="True"/>
          <Option Name="Do not use" Value="False"/>
        </FieldBind>
        <FieldBind Field="NewSiteUrl" DesignerType="ParameterNames" Id="6"/>
      </RuleDesigner>
      <Parameters>
        <Parameter Name="__Context" 
            Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" 
            Direction="In"/>
        <Parameter Name="UrlName" Type="System.String, mscorlib" Direction="In" />
        <Parameter Name="SiteTemplateTitle" Type="System.String, mscorlib" Direction="In" />
        <Parameter Name="SiteTitle" Type="System.String, mscorlib" Direction="In" />
        <Parameter Name="SiteDescription" Type="System.String, mscorlib" Direction="In" />
        <Parameter Name="UseUniquePermissions" Type="System.String, mscorlib" Direction="In" />
        <Parameter Name="NewSiteUrl" Type="System.String, mscorlib" Direction="Out" />
      </Parameters>
    </Action>
  </Actions>
</WorkflowInfo>

blog comments powered by Disqus