在SharePoint 2010中实现View Action Button效果。

http://www.sharepointblogs.be/blogs/vandest/archive/2008/06/20/view-action-button.aspx

1. 创建自定义字段类ViewActionButton 继承自 SPTextField

    public class ViewActionButton : SPField
{
#region Constructors
public ViewActionButton(SPFieldCollection fields, string fieldName)
: base(fields, fieldName) { } public ViewActionButton(SPFieldCollection fields, string typeName, string displayName)
: base(fields, typeName, displayName) { }
#endregion #region Reimplementation of Get/Set Custom Property
public new void SetCustomProperty(string propertyName, object propertyValue)
{
Type type = typeof(SPField);
MethodInfo setField = type.GetMethod("SetFieldAttributeValue", BindingFlags.NonPublic | BindingFlags.Instance);
object o = setField.Invoke(this, new object[] { propertyName, propertyValue.ToString() });
} public new string GetCustomProperty(string propertyName)
{
Type type = typeof(SPField);
MethodInfo getField = type.GetMethod("GetFieldAttributeValue", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(String) }, null);
object o = getField.Invoke(this, new object[] { propertyName }); return o as String;
}
#endregion
}

2. 创建字段属性用户控件ActionButtonPropertyControl

ActionButtonPropertyControl.ascx

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormControl" src="~/_controltemplates/InputFormControl.ascx" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ActionButtonPropertyControl.ascx.cs" Inherits="CustomFieldProject.ControlTemplates.ViewActionButton.ActionButtonPropertyControl" %>
<wssuc:InputFormControl runat="server" LabelText="Action URL:">
<Template_Control>
<span style="white-space: nowrap;">
<SharePoint:ProjectProperty runat="server" Property="Url" />/
<SharePoint:InputFormTextBox ID="iftxtUrl" runat="server" CssClass="ms-input" TextMode="SingleLine" Width="" />
<asp:RequiredFieldValidator ID="rfvUrl" runat="server" ControlToValidate="iftxtUrl" Display="Dynamic" ErrorMessage="*" />
</span>
</Template_Control>
</wssuc:InputFormControl> <wssuc:InputFormControl runat="server" LabelText="Format:">
<Template_Control>
<asp:DropDownList ID="ifrbFormat" runat="server">
<asp:ListItem Selected="True" Value="Button" Text="Button" />
<asp:ListItem Selected="False" Value="Hyperlink" Text="Hyperlink" />
</asp:DropDownList>
</Template_Control>
</wssuc:InputFormControl> <wssuc:InputFormControl runat="server" LabelText="CSS-Class:">
<Template_Control>
<SharePoint:InputFormTextBox ID="iftxtCssClass" runat="server" CssClass="ms-input" TextMode="SingleLine" Text="ms-ButtonHeightWidth" />
<asp:RequiredFieldValidator ID="rfvCssClass" runat="server" ControlToValidate="iftxtCssClass" Display="Dynamic" ErrorMessage="*" />
</Template_Control>
</wssuc:InputFormControl>

请根据实际情况修改下列内容:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ActionButtonPropertyControl.ascx.cs" Inherits="CustomFieldProject.ControlTemplates.ViewActionButton.ActionButtonPropertyControl" %>

ActionButtonPropertyControl.ascx.cs

    public partial class ActionButtonPropertyControl : UserControl, IFieldEditor
{
#region Controls and Properties to get/set value of Controls
// protected InputFormTextBox iftxtUrl;
public string ActionURL
{
get { return iftxtUrl.Text; }
set { iftxtUrl.Text = value; }
} //protected DropDownList ifrbFormat;
public string Format
{
get { return ifrbFormat.SelectedValue; }
set { ifrbFormat.SelectedValue = value; }
} //protected InputFormTextBox iftxtCssClass;
public string CssClass
{
get { return iftxtCssClass.Text; }
set { iftxtCssClass.Text = value; }
}
#endregion #region IFieldEditor Members
public bool DisplayAsNewSection
{
get { return false; }
} public void InitializeWithField(SPField field)
{
// If it's no postback (first time loading on Edit Field)
if (!IsPostBack)
{
CustomFieldTypes.ViewActionButton myField = field as CustomFieldTypes.ViewActionButton;
if (null != myField)
{
// Set values in control based on values in myField
Type type = typeof(ActionButtonPropertyControl); foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
if (prop.CanWrite)
prop.SetValue(this, myField.GetCustomProperty(prop.Name), null);
}
}
}
} public void OnSaveChange(SPField field, bool isNewField)
{
CustomFieldTypes.ViewActionButton myField = field as CustomFieldTypes.ViewActionButton; if (null != myField)
{
// Set values in myField based on values in control
Type type = typeof(ActionButtonPropertyControl); foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
if (prop.CanWrite)
myField.SetCustomProperty(prop.Name, prop.GetValue(this, null));
}
}
}
#endregion
}

3. 创建自定义字段定义文件fldtypes_ViewActionButton

<?xml version="1.0" encoding="utf-8" ?>

<FieldTypes>
<FieldType>
<Field Name="TypeName">ViewActionButton</Field>
<Field Name="TypeDisplayName">View Action Button</Field>
<Field Name="TypeShortDescription">View Action Button</Field>
<Field Name="ParentType">Text</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowOnListCreate">TRUE</Field>
<Field Name="ShowOnSurveyCreate">TRUE</Field>
<Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
<Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
<Field Name="Sortable">FALSE</Field>
<Field Name="Filterable">FALSE</Field>
<Field Name="CAMLRendering">TRUE</Field>
<Field Name="FieldEditorUserControl">/_controltemplates/ViewActionButton/ActionButtonPropertyControl.ascx</Field>
<Field Name="FieldTypeClass">CustomFieldProject.CustomFieldTypes.ViewActionButton, $SharePoint.Project.AssemblyFullName$</Field> <RenderPattern Name="DisplayPattern">
<SetVar Name="ActionURLWithParams">
<HttpVDir CurrentWeb="TRUE" />
<HTML>/</HTML>
<Property Select="ActionURL"/>
<HTML>
<![CDATA[?ID=]]>
</HTML>
<Column Name="ID" />
<HTML>
<![CDATA[&List=]]>
</HTML>
<ListProperty Select="Name" />
</SetVar> <Switch>
<Expr>
<Property Select="Format"/>
</Expr>
<Case Value="Button">
<HTML>
<![CDATA[<input type="button" class="]]>
</HTML>
<Property Select="CssClass"/>
<HTML>
<![CDATA[" value="]]>
</HTML>
<Property Select="DisplayName"/>
<HTML>
<![CDATA[" onclick="javascript:window.location=STSPageUrlValidation(']]>
</HTML>
<GetVar Name="ActionURLWithParams" />
<HTML>
<![CDATA[&Source=' + GetSource()); return false;" />]]>
</HTML>
</Case>
<Case Value="Hyperlink">
<HTML>
<![CDATA[<a class="]]>
</HTML>
<Property Select="CssClass"/>
<HTML>
<![CDATA[" href="]]>
</HTML>
<GetVar Name="ActionURLWithParams" />
<HTML>
<![CDATA[" onclick="javascript:this.href = unescapeProperly(escape(this.href)); GoToLink(this); return false;">]]>
</HTML>
<Property Select="DisplayName"/>
<HTML>
<![CDATA[<a />]]>
</HTML>
</Case>
<Default>
<HTML><![CDATA[<span style="font-style: italic;">Invalid format</span>]]></HTML>
</Default>
</Switch>
</RenderPattern>
<RenderPattern Name="EditPattern"></RenderPattern>
<RenderPattern Name="NewPattern" DisplayName="NewPattern"></RenderPattern>
<RenderPattern Name="PreviewDisplayPattern">
<HTML><![CDATA[<span style="font-style: italic;">View Action Button</span>]]></HTML>
</RenderPattern>
<RenderPattern Name="PreviewEditPattern"></RenderPattern>
<RenderPattern Name="PreviewNewPattern"></RenderPattern>
</FieldType>
</FieldTypes>

由于在SharePoint 2010中已经不推荐使用RenderPattern方式来呈现字段,需要将“CAMLRendering”设置成True,否则需要通过自定义XSLT来实现。

<Field Name="CAMLRendering">TRUE</Field>

请根据实际情况修改下列内容:

<Field Name="FieldTypeClass">CustomFieldProject.CustomFieldTypes.ViewActionButton, $SharePoint.Project.AssemblyFullName$</Field>

4. 创建自定义XSLT样式文件

如果已经CAMLRendering设置成True,则不必自定义XSLT样式。

目前仍然没有找到方法能够在XSLT中读取字段的自定义属性。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal"> <xsl:template match ="FieldRef[@FieldType='ViewActionButton']" mode="Text_body">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="ActionURL" select="current()/@ActionURL" />
<xsl:variable name="Format" select="current()/@Format" />
<xsl:variable name="CssClass" select="current()/@CssClass" /> <xsl:choose>
<xsl:when test="$Format='Button'">
<input type="button">
<xsl:attribute name="class">
<xsl:value-of select="$CssClass"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="$thisNode/@Name"/>
</xsl:attribute>
<xsl:attribute name="onclick">
javascript:window.location=STSPageUrlValidation('$ActionURL?ID=$thisNode/@ID&amp;List=$List');
</xsl:attribute>
</input>
</xsl:when>
<xsl:otherwise>
<a target="_blank">
<xsl:attribute name="class">
<xsl:value-of select="$CssClass"/>
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="$ActionURL" />?ID=<xsl:value-of select="$thisNode/@ID" />&amp;List=<xsl:value-of select="$List" />
</xsl:attribute>
<xsl:value-of select="current()/@DisplayName"/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

fldtypes_ViewActionButton.xsl

5. 下载

ViewActionButton.zip

[SharePoint 2010] 自定义字段类型开发(二)的更多相关文章

  1. SharePoint 2010 自定义 字段 类型--------省市区联动

    转:http://www.cnblogs.com/sp007/p/3384310.html 最近有几个朋友问到了有关自定义字段类型的问题,为了让更多的人了解自定义字段类型的方法,特写一篇博客与大家分享 ...

  2. 转载:SharePoint 2010 自定义 字段 类型--------省市区联动

    最近有几个朋友问到了有关自定义字段类型的问题,为了让更多的人了解自定义字段类型的方法,特写一篇博客与大家分享,首先看一下解决方案目录 创建自定义类型分以下几个步骤: 第一步:添加SharePoint映 ...

  3. 开发MOSS自定义字段类型

    前段时间,由于刚好项目定制的需要,笔者就开发了几个自定义字段类型.在这抽空做个详细笔记,方便初学者学习.这方面的资料也很多,如果自身觉得不大明白可以参考下SDK和网上的相关文章.本章的目的主要是给新手 ...

  4. sharepoint2010问卷调查(3)-实现问卷的开始和结束时间(采用自定义字段类型)

    接着上面的图片调查,sharepoint自带的问卷调查是没有开始和结束时间的.这个在项目过程不太实用.问卷一般有开始和结束时间的.因此需要自己 动手开发一个自定义字段类型字段.如下图: 开发添加栏目会 ...

  5. sharepoint2010问卷调查(2)-实现问卷的图片调查(采用自定义字段类型)

    1. 首先建立个图片库上传图片 并建立文件夹1和2,1下有1.1文件夹,2下2.1文件夹,2.1下有文件夹2.1.1. 在1文件夹下放如下图片: 2.建立自定义字段类型,如下图: 3.部署后建立栏目的 ...

  6. SharePoint 2010 ——自定义上传页面与多文件上传解决方案

    最近项目遇到一个很麻烦的问题,原以为很容易解决,结果搞了那么久,先开个头,再慢慢写 SharePoint 2010 ——自定义上传页面与多文件上传解决方案 1.创建Sharepoint空白项目,创建应 ...

  7. sharepoint 2010自定义访问日志列表设置移动终端否和客户端访问系统等计算列的公式

    上个月本人开发和上线了一个在SharePoint 2010上基于HTML5的移动OA网站,后端服务采用自定义的基于AgilePoint工作流引擎的Sharepoint Web服务,前端主要采用Jque ...

  8. SharePoint 2010自定义母版页小技巧——JavaScript和CSS引用

    通常在我们的项目中,都会涉及到母版页的定制.并且必不可少的,需要配合以一套自己的JavaScript框架和CSS样式.你有没有遇到过这样的情况呢,在开发环境和UAT时都还算顺利,但是当最终部署到生产服 ...

  9. SharePoint 2013 自定义扩展菜单(二)

    接博文<SharePoint 2013 自定义扩展菜单>,多加了几个例子,方便大家理解. 例七 列表设置菜单扩展(listedit.aspx) 扩展效果 XML描述 <CustomA ...

随机推荐

  1. xamarin.Android 标记1

    群里一个朋友的博客 推荐一下 自己也做个书签记录. http://sunyt.me/2015/04/15/Xamarin-FAQ/

  2. Hibernate关联关系的映射

    实体之间的关系 实体之间有三种关系 一对多:一个用户,生成多个订单,每一个订单只能属于一个用户 建表原则:在多的一方创建一个字段,作为外键,指向一的一方的主键 多对多:一个学生可以选择多门课程,一个课 ...

  3. wpf图片查看器,支持鼠标滚动缩放拖拽

    最近项目需要,要用到一个图片查看器,类似于windows自带的图片查看器那样,鼠标滚动可以缩放,可以拖拽图片,于是就写了这个简单的图片查看器. 前台代码: <Window x:Class=&qu ...

  4. iOS--创建炫酷的渐变色界面

    { CAGradientLayer *_layer; } //创建渐变层 _layer =[CAGradientLayer layer]; _layer.frame=self.view.frame; ...

  5. dbflow 批量 增删查改

    @ModelContainer @Table(database = DemoDatabase.class) class Person extends BaseModel implements Seri ...

  6. Leetcode Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  7. 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP

    题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...

  8. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  9. ios 计算缓存大小并清理缓存

    SDWebImage.WebView产生的缓存 1.计算缓存大小 //SDWebImage缓存大小  UILabel *cleanDetailText = [[UILabel alloc]init]; ...

  10. 李洪强iOS经典面试题143-绘图与动画

    李洪强iOS经典面试题143-绘图与动画   绘图与动画 CAAnimation的层级结构 CAPropertyAnimation是CAAnimation的子类,也是个抽象类,要想创建动画对象,应该使 ...