0
votes

I am trying to create a custom workflow in Visual Studio 2010 for SharePoint 2010 and have run into a problem. I have figured out how to deploy the workflow to the SharePoint site, but executing it results in an error. However, the error message is completely non-descriptive, so I want to find out if there is a way to execute it from Visual Studio so I can see where it fails, and possibly why.

I'm trying to simply create a new subsite based on a given ListItem.Title information.

How is it you go about debugging?

For reference, here is my code

class CreateSubsite : System.Workflow.ComponentModel.Activity
{
    protected override System.Workflow.ComponentModel.ActivityExecutionStatus
        Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
    {
        createSite();
        return System.Workflow.ComponentModel.ActivityExecutionStatus.Closed;
    }

    public void createSite()
    {
        using (SPSite currentSite = SPContext.Current.Site)
        {
            using (SPWeb currentWeb = SPContext.Current.Web)
            {
                SPList currentList = SPContext.Current.List;
                SPListItem currentListItem = SPContext.Current.ListItem;

                WorkflowContext workflow = new WorkflowContext();
                SPSite parentSite = new SPSite(workflow.CurrentWebUrl);

                SPWeb newSite = currentSite.AllWebs.Add(
                    currentListItem.Title.Replace(" ", "_"),
                    currentListItem.Title,
                    String.Empty, currentWeb.Language, "CI Template", false, false
                );
            }
        }
    }
}
1

1 Answers

0
votes

Try to remove Using keyword from your code .You should not dispose your SPSite and SPWeb when you use SPContext because disposing of that object might actually break the workflow as it may still need a reference to that object for later use. just rewrite your code without use using

  public void createSite() {
        SPSite currentSite = SPContext.Current.Site 
        SPWeb currentWeb = SPContext.Current.Web
         //.... Rest of your code

Hope that help Regards.