【问题标题】:Testing SharePoint List Workflow from Visual Studio 2010从 Visual Studio 2010 测试 SharePoint 列表工作流
【发布时间】:2011-12-14 18:05:25
【问题描述】:

我正在尝试在 Visual Studio 2010 中为 SharePoint 2010 创建自定义工作流,但遇到了问题。我已经弄清楚如何将工作流部署到 ​​SharePoint 网站,但执行它会导致错误。但是,错误消息是完全非描述性的,所以我想知道是否有办法从 Visual Studio 中执行它,这样我就可以看到它失败的地方,以及可能的原因。

我正在尝试根据给定的ListItem.Title 信息简单地创建一个新的子网站。

你是怎么调试的?

供参考,这是我的代码

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
                );
            }
        }
    }
}

【问题讨论】:

    标签: visual-studio-2010 sharepoint-2010


    【解决方案1】:

    尝试从代码中删除 Using 关键字。使用 SPContext 时不应释放 SPSite 和 SPWeb,因为释放该对象实际上可能会破坏工作流程,因为它可能仍需要对该对象的引用对象供以后使用。 只需使用

    重写你的代码
      public void createSite() {
            SPSite currentSite = SPContext.Current.Site 
            SPWeb currentWeb = SPContext.Current.Web
             //.... Rest of your code
    

    希望有所帮助 问候。

    【讨论】:

    • 谢谢!我发现了 Intellitrace,这就是我目前正在努力理解和使用的东西。
    • 如果有人偶然发现这一点,我最终部署了工作流,在我的站点上启用它,运行工作流,然后搜索位于“C:\Program Files\Common Files\Microsoft Shared”中的日志文件\Web Server Extensions\14\LOGS" 我还发现您不能在 Workflow 中使用 SPContext(它返回 null 并导致 Workflow 出错)来源:here
    猜你喜欢
    • 1970-01-01
    • 2011-04-30
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 2011-08-24
    相关资源
    最近更新 更多