SPS中文件放在文档库中,文档库默认的菜单有很多功能,但我们想自己添加菜单行不行呢?答案当然是可以的,oliverlu 的这边文章http://blogs.msdn.com/oliverlu/articles/222265.aspx介绍了两种添加文档库菜单的方法,特别是他利用内容编辑器Web部件来加入JS代码重写菜单项的方法可以很方便的定制菜单项,同时也避免了SDK中那种方法很多不足之处。但是当我们编写复杂菜单项事件,需要重新写ASPX页来定义函数响应菜单项事件时,页面的前台编码ASPX并没有智能提示,很难进行控制和编译,那可不可以用ASPX页的后台编码来控制呢?那样既有智能提示,提高编码效率,因为是后台编码可以编译为DLL文件,提高代码安全性。我的一个同事找到了一个办法,现在把它共享出来,希望对大家有所帮助。
当然首先还是按照oliverlu的方法在一个隐藏的内容编辑器Web部件源编译器输入下面的代码:
<script language="javascript">
function AddCheckinCheckoutMenuItem(m, ctx, url)
{
if (currentItemCheckedOutUserId == null)
currentItemCheckedOutUserId = itemTable.COUId;
if (currentItemCheckedOutUserId != "")
{
strDisplayText = L_Checkin_Text;
strAction = "NavigateToCheckinAspx('" + ctx.HttpRoot + "', 'FileName=" + url + "')";
strImagePath = ctx.imagesPath + "checkin.gif";
CAMOpt(m, strDisplayText, strAction, strImagePath);
}
else
{
strDisplayText = L_Checkout_Text;
strAction = "NavigateToCheckinAspx('" + ctx.HttpRoot + "', 'FileName=" + url + "&Checkout=true')";
strImagePath = ctx.imagesPath + "checkout.gif";
CAMOpt(m, strDisplayText, strAction, strImagePath);
strAction = "ItemSay('" + ctx.HttpRoot + "', 'FileName=" + url + "&Checkout=true')";
CAMOpt(m, "Say", strAction, strImagePath);
CAMSep(m);
}
}
function ItemSay(strHttpRoot, strArgs)
{
window.onfocus = RefreshOnNextFocus;
SubmitFormPost(strHttpRoot + "/_layouts/" + L_Language_Text +
"/ItemSay.aspx?" + strArgs + "&Source=" + GetSource());
}
</script>
上面代码的意思就是加入一个菜单项叫Say,当点击它时将调用ItemSay函数,而这个函数又将调用ItemSay.aspx页。
在页面菜单的显示效果如下图:
下面我们要做的就是写这个ItemSay.aspx页了,在.net中新建一个空的Web项目,在项目中添加一个新的aspx页,取名叫ItemSay.aspx,双击这个页面到它的后台编码,写入下列代码:
当然在Page_Load你可以写入任何你想要的操作,现在我们只是让他显示“Hello World!”,在ItemSay.aspx的HTML页中的第一行中加入EnableViewStateMac="false"这一项。结果如下所示:
<%@ Page language="c#" Codebehind="ItemSay.aspx.cs" AutoEventWireup="false" Inherits="ItemEvent.ItemSay" EnableViewStateMac="false" %> 然后编译。编译完成后将ItemSay.aspx拷到Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS\LanguareID目录下,编译的dll文件拷到C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\BIN目录下。
到这所有的操作都已完成,现在点文档库的Say菜单时,将会出现一个新的ItemSay.aspx页,页面显示为"Hello World!"。
这种用后台编码的方法可以充分利用智能提示,这样的话编译,Coding的时候都方便很多,并且最后编译成dll文件,代码的安全性也得到了很大的提高。
我们现在正在用这种方法模仿kaneboy的workflow来做审批流程:当用户一篇文档要审批他点击审批菜单后,文档就自动Copy到相应的文档库中,以此来实现文档的流转过程。
当然首先还是按照oliverlu的方法在一个隐藏的内容编辑器Web部件源编译器输入下面的代码:
<script language="javascript">
function AddCheckinCheckoutMenuItem(m, ctx, url)
{
if (currentItemCheckedOutUserId == null)
currentItemCheckedOutUserId = itemTable.COUId;
if (currentItemCheckedOutUserId != "")
{
strDisplayText = L_Checkin_Text;
strAction = "NavigateToCheckinAspx('" + ctx.HttpRoot + "', 'FileName=" + url + "')";
strImagePath = ctx.imagesPath + "checkin.gif";
CAMOpt(m, strDisplayText, strAction, strImagePath);
}
else
{
strDisplayText = L_Checkout_Text;
strAction = "NavigateToCheckinAspx('" + ctx.HttpRoot + "', 'FileName=" + url + "&Checkout=true')";
strImagePath = ctx.imagesPath + "checkout.gif";
CAMOpt(m, strDisplayText, strAction, strImagePath);
strAction = "ItemSay('" + ctx.HttpRoot + "', 'FileName=" + url + "&Checkout=true')";
CAMOpt(m, "Say", strAction, strImagePath);
CAMSep(m);
}
}
function ItemSay(strHttpRoot, strArgs)
{
window.onfocus = RefreshOnNextFocus;
SubmitFormPost(strHttpRoot + "/_layouts/" + L_Language_Text +
"/ItemSay.aspx?" + strArgs + "&Source=" + GetSource());
}
</script>
上面代码的意思就是加入一个菜单项叫Say,当点击它时将调用ItemSay函数,而这个函数又将调用ItemSay.aspx页。
在页面菜单的显示效果如下图:
下面我们要做的就是写这个ItemSay.aspx页了,在.net中新建一个空的Web项目,在项目中添加一个新的aspx页,取名叫ItemSay.aspx,双击这个页面到它的后台编码,写入下列代码:
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11
12namespace ItemEvent
13{
14 /// <summary>
15 /// ItemSay 的摘要说明。
16 /// </summary>
17 public class ItemSay : System.Web.UI.Page
18 {
19 private void Page_Load(object sender, System.EventArgs e)
20 {
21 Response.Write("Hello world!");
22 // 在此处放置用户代码以初始化页面
23 }
24
25 Web 窗体设计器生成的代码
45 }
46}
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11
12namespace ItemEvent
13{
14 /// <summary>
15 /// ItemSay 的摘要说明。
16 /// </summary>
17 public class ItemSay : System.Web.UI.Page
18 {
19 private void Page_Load(object sender, System.EventArgs e)
20 {
21 Response.Write("Hello world!");
22 // 在此处放置用户代码以初始化页面
23 }
24
25 Web 窗体设计器生成的代码
45 }
46}
当然在Page_Load你可以写入任何你想要的操作,现在我们只是让他显示“Hello World!”,在ItemSay.aspx的HTML页中的第一行中加入EnableViewStateMac="false"这一项。结果如下所示:
<%@ Page language="c#" Codebehind="ItemSay.aspx.cs" AutoEventWireup="false" Inherits="ItemEvent.ItemSay" EnableViewStateMac="false" %>
<%@ Page language="c#" Codebehind="ItemSay.aspx.cs" AutoEventWireup="false" Inherits="ItemEvent.ItemSay" EnableViewStateMac="false" %> 然后编译。编译完成后将ItemSay.aspx拷到Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS\LanguareID目录下,编译的dll文件拷到C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\BIN目录下。
到这所有的操作都已完成,现在点文档库的Say菜单时,将会出现一个新的ItemSay.aspx页,页面显示为"Hello World!"。
这种用后台编码的方法可以充分利用智能提示,这样的话编译,Coding的时候都方便很多,并且最后编译成dll文件,代码的安全性也得到了很大的提高。
我们现在正在用这种方法模仿kaneboy的workflow来做审批流程:当用户一篇文档要审批他点击审批菜单后,文档就自动Copy到相应的文档库中,以此来实现文档的流转过程。