设为首页 收藏本站
查看: 913|回复: 0

[经验分享] Import a SharePoint Designer Reusable Workflow into Visual Studio in SharePoint

[复制链接]

尚未签到

发表于 2017-5-24 09:54:51 | 显示全部楼层 |阅读模式
Step by step import reuseable workflow in SharePoint 2013 by Visual Studio
  This walkthrough demonstrates how to import a reusable workflow created in SharePoint Designer 2013 into a Visual Studio SharePoint workflow project.
  Workflows created in SharePoint Designer, or declarative workflows, consist of XML statements instead of code. SharePoint Designer 2013 introducesreusable workflows, which are portable, declarativeworkflows that can be used by different lists in SharePoint sites.
  Workflows created in Visual Studio 2013, such as sequential and state machine workflows, are calledcode workflows. Code workflows consist of XML files and code modules in which users can customize the workflow's behavior.
  Visual Studio allows you to import reusable workflows created in SharePoint Designer 2013 and convert them to code workflows for use in your SharePoint sites.
  This walkthrough demonstrates the following tasks:

  •   Creating a simple, reusable workflow in SharePoint Designer.
  •   Exporting the SharePoint Designer reusable workflow to a .wsp file and into SharePoint.
  •   Importing the .wsp file into Visual Studio by using the Import Reusable Workflow project.
  •   Altering the workflow by adding code.
  •   Using the imported workflow in a SharePoint site.
Create a SharePoint Designer Reusable Workflow

Because SharePoint does not include any reusable workflows that you can use for this example, you will create one.In this simple workflow, when a user enters anew task in the Task list that has a specific title, the task is assigned to that user.
Create Target SharePoint Subsites


First you create two new SharePoint subsites: one to host the reusable workflows from SharePoint Designer, another to host the converted workflows.
To create SharePoint subsites

  •   In SharePoint Designer 2010, on the menu bar, chooseFile,New Blank Web Site
  •   In theNew Blank Web Site dialog box, browse to a SharePoint site where you want to create the workflow, or use the value of http://SystemName/and then choose theOK button.The Home page appears.

DSC0000.png

  •   In the Subsites section, choose the New button.
  •   In the New dialog box, choose SharePoint Templates from the list in the left pane, and chooseTeam Site from the list in the right pane.
  •   In the Specify the location of the Web site box, replace the word subsite in the URL with SPD1, and then choose the OK button.

DSC0001.png

  •   This opens the new subsite into SharePoint Designer.Close this instance of SharePoint Designer and go back to the first instance (the top-level site).
  •   Repeat steps 3 - 5 to create the second subsite, this time replacing the wordsubsite in the URL with SPD2.

   DSC0002.png
To create a SharePoint Designer reusable workflow

  •   In the Subsites section, choose theSPD1 site to modify it.
  •   On the ribbon, choose the Reusable Workflow button.
      The Create Reusable Workflow wizard appears.
  •   In the Name box, enter SPD Task Workflow.
  •   In the Content Type list, chooseTask, and then choose theOK button.
      The workflow opens in the SharePoint Designer workflow designer.

   DSC0003.png

  •   In the workflow designer, choose Step 1, and then, on the ribbon, choose theCondition button.
  •   In the list of conditions, choose If current item field equals value.
      This step adds a condition that’s named If field equals value.
  •   In the If field equals value condition, choose thefield link.
  •   In the list of values, choose Title.
  •   In the If field equals value condition, choose thevalue link.
  •   In the box, enter New task.
      The condition statement now reads If Current Item:Title equals New task.
  •   Choose the line under the condition statement, and then, on the ribbon, choose theAction button.
  •   In the list of actions, choose Set field in current item.
  •   In the Set field to value action, choose thefield link, and then, in the list, chooseAssigned to.
  •   In the Set field to value action, choose thevalue link, and then, in the list of existing users and groups, chooseUser who created the item.
  •   Choose the Add button, and then choose theOK button.
      The action statement now reads Set Assigned To to Current Item:CreatedBy.
   DSC0004.png
Save and Deploy the Reusable Workflow

Because Visual Studio can import only .wsp files, you must save the reusable workflow as a .wsp file and deploy it to SharePoint before importing it into Visual Studio.
DSC0005.png Important  If you receive a runtime error performing the following procedure, you have to perform the procedure on a system that has access to the SharePoint site.

To save and deploy the reusable workflow

  •   At the top of SharePoint Designer, choose theSave button to save your progress, and then choose thePublish button to deploy the workflow to theSPD1SharePoint site.
  •   In the Navigation pane, choose the Workflows object.
  •   Under Reusable Workflow, chooseSPD Task Workflow.
  •   On the ribbon, choose the Save as Template button to save the workflow as a .wsp file.

DSC0006.png

  •   Open the SPD1 SharePoint site in a browser to view the .wsp file in SharePoint.
  •   Search the template in SPD1

DSC0007.png


  •   In the File Download dialog box, choose theSave button to save the .wsp file on your local system.
   DSC0008.png
  
Import the .wsp File into Visual Studio

Import the .wsp file into Visual Studio by using an Import Reusable Workflow project.This project converts the workflow from a reusable, declarative workflow intoa code workflow.After the workflow is converted, you will use code to modify its behavior.
To import a workflow from a .wsp file and modify it

  •   In Visual Studio, on the menu bar, choose File, New, Project.

DSC0009.png

  •   In the New Project dialog box, expand theSharePoint node under eitherVisual C# orVisual Basic, and then choose the2010node.
  •   In the Templates pane, choose theImport Reusable SharePoint 2010 Workflow template, leave the name of the project asWorkflowImportProject1,and then choose the OK button.
      The SharePoint Customization Wizard appears.

  

  •   On the Specify the site and security level for debugging page, enter the URL for the second SharePoint subsite that you created previously: http://system name/SPD2.
   DSC00010.gif

  •   In the What is the trust level for this SharePoint solution? section, choose theDeploy as a farm solution option button, and then choose theNextbutton.
  
  
  For more information about sandboxed versus farm solutions, seeSandboxed Solution Considerations.

  •   In the Specify the new project source page, browse to the location on the system where you previously saved the .wsp file, open the file, and then choose theNext button.
    Note  Choose the Finish button to import all available items in the .wsp file.

      This displays a list of reusable workflows available for importing.
  •   In the Select items to import box, choose theSPD Task Workflow workflow, and then choose theFinish button.
      After the import operation is finished, a project namedWorkflowImportProject1 is created containing a workflow namedSPD_Workflow_TestFT.Inthis folder is the workflow's definition file Elements.xml and the workflow designer file (.xoml).The designer contains two files: the rules file (.rules) and the code-behind file (either .cs or .vb, depending on yourproject's programming language).
  •   In Solution Explorer, chooseWorkflowImportProject1, and then, on the menu bar, chooseProject,Set as Startup Projectto setWorkflowImportProject1 as the Startup Item.
      This displays the list immediately when you debug the project.
  •   Because the Import Reusable SharePoint 2010 Workflow template doesn’t import the association property values for the imported workflow, you must enter them.Todo this:

    •   In Solution Explorer, choose theSPD_Workflow_TestFT node.
    •   Choose the ellipsis ( DSC00011.png ) button next to one of the list properties, suchas the Target List property.
    •   Fill in the missing values in the SharePoint Customization Wizard, and then choose theFinish button.

  •   Choose the .xoml file, and then, on the menu bar, chooseView,Designer to view the imported workflow in the workflow designer.
  •   In the Windows Workflow v3.0 node of theToolbox, perform one of the following steps:

    •   Open the shortcut menu for the Code activity, and then choose Copy.In the workflow designer, open the shortcut menu for the line under theSequenceActivity1 activity, and then choosePaste.
    •   Drag the Code activity from theToolbox to the workflow designer, and connect it to the line under theSequenceActivity1 activity.
      This adds an activity to the workflow designer namedCodeActivity1.In this activity, you will add a code action that creates an announcement in the Announcementslist when the user starts the workflow.

   DSC00012.png
   DSC00013.png
   DSC00014.png
Deploy the Project and Associate the Workflow

Next, run WorkflowImportProject1 to deploy it to a SharePoint site and then associate the workflow with the Tasks list to view and test the modified, converted workflow.
To deploy the project and associate the workflow

  •   In Visual Studio, choose the F5 key to run and deploy the converted workflow project.
  •   On the QuickLaunch bar, choose the Tasks link to display the Tasks list.
  •   On the List Tools tab, choose theItems button, and then choose theNew Item button.
      The Tasks - New Item dialog box opens.
  •   In the Title box, enter New task, and then choose theSave button.
  •   On the List Tools tab, choose theList button, and then choose theList Settings button.
      The List Settings page appears.
  •   In the Permissions and Management section, choose theWorkflow Settings link.
      The Workflow Settings page appears.
  •   Choose the Add a Workflow link.
  •   In the Workflow list, chooseWorkflowImportProject1 - SPD Workflow Test.
  •   In the Name box, enter SPD Workflow Test, and then choose theOK button.
  •   In the QuickLaunch bar, choose the Tasks list.
  •   Choose the arrow next to New task, and then, in the list, choose Workflows.
  •   In the Start a New Workflow section, choose the link forSPD Workflow Test, and then choose theStart button to initiate the workflow.

DSC00015.png

Hope to help you,
The detail link to:http://msdn.microsoft.com/zh-cn/library/ee231580.aspx

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-380338-1-1.html 上篇帖子: Lose sharepoint site (forms-auth) administration rights 下篇帖子: Approach to upgrading custom SharePoint workflows
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表