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

[经验分享] SharePoint开发学习笔记4——使用aspx自定义表单的工作流(1)

[复制链接]

尚未签到

发表于 2015-9-25 13:27:25 | 显示全部楼层 |阅读模式
  此次完成的工作流任务就是一个基本的审批流程。
  
  以前在VS2008上开发SharePoint时要使用aspx页面的自定义关联表单或者初始化表单是比较麻烦的,需要自己把SP中的母版等其它东西参照着它的页面进行手动添加,而且还需要自己来获得上一页的表单数据,以及手动建立表单数据传递到下一页面。但到了VS2010中后,一切都变得简单了,它现在可以自动生成关联表单模板和初始化表单模板,而不用再操心样式和数据传递的问题了。(如下图)
  
DSC0000.png
  
  下面我们打开VS2010选择SharePoint项目模板,创建一个顺序工作流的工程;
  
DSC0001.png
  选择部署为form soluation,然后再选择为list workflow,最后关联好你调试时用的list后一直按Next就行了。
  
  然后在工程列表上右键,添加对Layouts目录的一个映射文件夹,因为只有添加了这个文件夹才能在它下面添加新项的时候才会有关联表单或者初始化表单的模板选择。
DSC0002.png
  创建关联表单
  这里简要说明一下什么是关联表单,我的理解就是在将WF与List或者Document等进行关联时填入一些默认的供WF初始化时自动填入的一些数据。当然,在关联表单页面还做了一些其它的操作,比如:创建一些List和WF关联信息存储、创建Task List和History List等等。
  
  在Layouts目录下右键,点击添加新项,在SharePoint项目模板中添加关联表单的选项。
DSC0003.png
  这样,关联表单就建好了。我们来看看它为我们做了些什么事。首先在页面上,已经为我们引入了需要的SP的程序集和关联好了站点中的母版页,我们主要修改的地方就是在ID为PlaceHolderMain下Content控件内部。
  
  在设计界面时,我还注册了另外两个SP的控件,InputFormSection和InputFormControl(因为有些SP控件有.ascx文件需要你用到时自己注册进来的,而有些直接用类写的就不用注册了。)
  
  



<%@ Register TagPrefix="wssuc" TagName="InputFormSection" Src="/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormControl" Src="/_controltemplates/InputFormControl.ascx" %>

  
  
  先看下整体效果吧:
  
DSC0004.png
  前台代码如下:(主要是PlaceHolderMain中的代码,其它地方未改动)
  



<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table border="0" cellspacing="0" cellpadding="0" class="ms-propertysheet" width="100%">
<colgroup>
<col />
<col />
</colgroup>
<tr>
<td>
<wssuc:InputFormSection ID="InputFormSection1" runat="server" Title="请选择指定人审批" Description="This is an example of AssociationForm.">
<template_inputformcontrols>
<wssuc:InputFormControl runat="server" LabelText="People:" LabelAssociatedControlId="SP_PeoleEditor">
<Template_Control>                  
<SharePoint:PeopleEditor runat="server" ID="SP_PeoleEditor" />
</Template_Control>
</wssuc:InputFormControl>
</template_inputformcontrols>
</wssuc:InputFormSection>
</td>
</tr>
<tr>
<td>
<wssuc:InputFormSection ID="InputFormSection3" runat="server" Title="请求信息" Description="This is an example of AssociationForm.">
<template_inputformcontrols>
<wssuc:InputFormControl runat="server" LabelAssociatedControlId="TextBox1">
<Template_Control>                  
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows="5"></asp:TextBox>
</Template_Control>
</wssuc:InputFormControl>
</template_inputformcontrols>
</wssuc:InputFormSection>
</td>
</tr>
<tr>
<td>
<wssuc:InputFormSection ID="InputFormSection2" runat="server" Title="确认关联" Description="This is an example of AssociationForm.">
<template_inputformcontrols>
<wssuc:InputFormControl runat="server" LabelAssociatedControlId="Panel1">
<Template_Control>  
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="AssociateWorkflow" runat="server" Text="Associate Workflow" />
<asp:Button ID="Cancel" runat="server" Text="Cancel" />
</asp:Panel>

</Template_Control>
</wssuc:InputFormControl>
</template_inputformcontrols>
</wssuc:InputFormSection>
</td>
</tr>
</table>
</asp:Content>

  
  
  最后看看后台代码。展开代码可以看到VS2010也为我们自动完成了很多事情,不用我们再操心数据的传递,任务列表和历史列表的一些繁琐的事情了,主要改动的地方就是在GetAssociationData()这个方法中。
  它的作用就是将XML序列化后(工作流中表单数据传递都是通过xml的形式)的数据保存进SPWorkflowAssociation中。所以还需要一个序列化的方法。
  


// This method is called when the user clicks the button to associate the workflow.
private string GetAssociationData()
{
ArrayList listName = SP_PeoleEditor.ResolvedEntities;
DataModel dataModel = new DataModel();
foreach (PickerEntity item in listName)
{
dataModel.Persons.Add(item.Key);
}
dataModel.RequestMessage = TextBox1.Text;
String xmlResult = xmlSerialize(dataModel);
return xmlResult;
}
private string xmlSerialize(DataModel dataModel)
{
using (MemoryStream ms = new MemoryStream())
{
XmlSerializer serializer = new XmlSerializer(typeof(DataModel));
serializer.Serialize(ms, dataModel);
byte[] bytes = new byte[ms.Length];
ms.Position = 0;
ms.Read(bytes, 0, bytes.Length);
return Encoding.Default.GetString(bytes);
}
}


  最后是DataModel,在工程中新建的一个需要传递的数据类,选择类文件创建就行了,但是要注意的一点就是类要标注序列化。
  


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Heqichang.WF.Demo1
{
[Serializable]
public class DataModel
{
private List<String> persons;
public List<String> Persons
{
get
{
if (persons==null)
{
persons = new List<string>();
}
return persons;
}
set
{
persons = value;
}
}
public String RequestMessage { get; set; }
}
}

运维网声明 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-118744-1-1.html 上篇帖子: SharePoint中用不存在的"对象名"获取"对象"时的异常处理 下篇帖子: 微软官方的 SharePoint 支持中心以及在线实验室
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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