MOSS点滴(2):自定义Application Page

简介:

在MOSS中后台管理的页面都是Application Page,比如网站设置的页面(settings.aspx)就是典型的Application Page,它不能被Sharepoint Desiger定制。如果我们要修改只能手动的使用其他工具来修改,我们也可以添加Application Page,必须放在C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS目录下,它对应的虚拟路径为_layouts。所有的Application Page都使用application.master这个母版页,我们自定义的Application Page也是一样,可以使用内嵌代码也可以使用后置代码。自定义的application page继承自LayoutsPageBase类,下面我们就来做两个自定义的Application Page,下面是项目的结构:

1

Feature.xml中代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="86689158-7048-4421-AD21-E0DEF0D67C81" 
   Title="自定义ApplicationPage"
   Description="使用SPTreeViw演示自定义ApplicationPage"
   Version="1.0.0.0"
   Scope="Web"
   Hidden="FALSE"         
   ImageUrl="TPG\PithHelmet.gif"         
   xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml" />
</ElementManifests>
</Feature>

ApplicationPage1.aspx和ApplicationPage2.aspx就是我们自定义的Application Page,ApplicationPage1.aspx演示的是在一个列表库的列表项的编辑菜单里出现一个链接,统计该列表的信息,如下图:

2

要添加此菜单须在Elements.xml中填加如下代码:

<!--  出现在控件的编辑项中 -->
< CustomAction  Id ="CustomApplicationPage1"
RegistrationType
="List"
RegistrationId
="101"
ImageUrl
="/_layouts/images/GORTL.GIF"
Location
="EditControlBlock"
Sequence
="240"
Title
="此文档库信息"   >
< UrlAction  Url ="~site/_layouts/CustomApplicationPages/ApplicationPage1.aspx?ItemId={ItemId}&amp;ListId={ListId}" />
</ CustomAction >


RegistrationType="List":代表注册的类型是列表.
Location="EditControlBlock":代表菜单将出现在控件编辑项当中.
UrlAction 是它的链接,URL中的ItemId 和ListId是通过 QueryString得到的。


ApplicationPage1.cs中代码如下:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace CustomApplicationPages 
{
   public  class ApplicationPage1 : LayoutsPageBase 
 {
     protected Label lblSiteTitle;
     protected Label lblSiteID;
     protected Label lblSiteUrl;
     protected Label lblListID;
     protected Label lblListTile;
     protected Label lblRootFolderUrl;
     protected Label lblDocumentID;
     protected Label lblDocumentName;
     protected Label lblDocumentUrl;
     protected Label lblDocumentTemplateUrl;
     protected Label lblFileAuthor;
     protected Label lblFileSize;
     protected Label lblFileLastModified;
     protected Label lblFileCheckOutStatus;

     protected  override  void OnLoad(EventArgs e) 
   {
      SPSite siteCollection =  this.Site;
      SPWeb site =  this.Web;
      lblSiteTitle.Text = site.Title;
      lblSiteUrl.Text = site.Url.ToLower();      
       string ListId = Request.QueryString[ " ListId "];
      lblListID.Text = ListId;
      SPList list = site.Lists[ new Guid(ListId)];
      lblListTile.Text = list.Title;
      lblRootFolderUrl.Text = list.RootFolder.Url;      
       string ItemId = Request.QueryString[ " ItemId "];
      lblDocumentID.Text = ItemId;
      SPListItem item = list.Items.GetItemById(Convert.ToInt32(ItemId));
      lblDocumentName.Text = item.Name;
      lblDocumentUrl.Text = item.Url;

       if (list  is SPDocumentLibrary)
    {
        SPDocumentLibrary documentLibrary = (SPDocumentLibrary)list;
        lblDocumentTemplateUrl.Text = documentLibrary.DocumentTemplateUrl;

        SPFile file = site.GetFile(item.Url);
        lblFileAuthor.Text = file.Author.Name;
        lblFileSize.Text = file.TotalLength.ToString( " 0,### ") +  "  bits ";
        lblFileLastModified.Text =  " By  " + file.ModifiedBy.Name +
                                    "  on  " + file.TimeLastModified.ToLocalTime().ToString();
        lblFileCheckOutStatus.Text = file.CheckOutStatus.ToString();
      }
    }
    
  }
}


结果如下图:

3

ApplicationPage2.aspx中我们使用控件SPTreeView来显示该站点的文件夹结构,我们将菜单添加到“网站操作“中,并且设置只有管理员权限才可以看到,如下图:

4

Elements.xml中填加如下代码:

<!--  有管理员权限才可以察看  -->
< CustomAction  Id ="CustomApplicationPage2"
GroupId
="SiteActions"
Location
="Microsoft.SharePoint.StandardMenu"
Sequence
="2006"
Title
="获取站点信息"
Description
="使用SPTreeView获取站点信息"
RequireSiteAdministrator
="True" >
< UrlAction  Url ="~site/_layouts/CustomApplicationPages/ApplicationPage2.aspx" />
</ CustomAction >


RequireSiteAdministrator="True":改属性说明该项操作只有拥有管理员权限的用户才可以操作

ApplicationPage2.cs中代码如下:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace CustomApplicationPages
{
   public  class ApplicationPage2 : LayoutsPageBase 
  {    
     protected SPTreeView treeSitesFiles;
     const  string siteImg =  @" \_layouts\images\FPWEB16.GIF ";
     const  string foloerImg =  @" \_layouts\images\FOLDER16.GIF ";
     const  string ghostedFileImg =  @" \_layouts\images\NEWDOC.GIF ";
     const  string unGhostedFileImg =  @" \_layouts\images\RAT16.GIF ";

     protected  override  void OnLoad(EventArgs e)
    {
      SPWeb site = SPContext.Current.Web;
      SPFolder rootFolder = site.RootFolder;
      TreeNode rootNode =  new TreeNode(site.Url, site.Url, siteImg);
      LoadFolderNodes(rootFolder, rootNode);
      treeSitesFiles.Nodes.Add(rootNode);
      treeSitesFiles.ExpandDepth =  1;
    }

     protected  void LoadFolderNodes(SPFolder folder, TreeNode folderNode)
    {
       foreach (SPFolder childFolder  in folder.SubFolders) 
      {
        TreeNode childFolderNode =  new TreeNode(childFolder.Name, childFolder.Name, foloerImg);
        childFolderNode.NavigateUrl = Site.MakeFullUrl(childFolder.Url);
        LoadFolderNodes(childFolder, childFolderNode);        
        folderNode.ChildNodes.Add(childFolderNode);
      }

       foreach (SPFile file  in folder.Files) 
      {
        TreeNode fileNode;
         if (file.CustomizedPageStatus == SPCustomizedPageStatus.Uncustomized) 
        {
            fileNode =  new TreeNode(file.Name, file.Name, ghostedFileImg);          
        }
         else 
        {
            fileNode =  new TreeNode(file.Name, file.Name, unGhostedFileImg);
        }
        fileNode.NavigateUrl = Site.MakeFullUrl(file.Url);
        folderNode.ChildNodes.Add(fileNode);
      }
    } 
  }
}


效果如下图:

5

如何调试:
1.修改当前web应用程序的配置文件如下:

 
 
< configuration >
   < SharePoint >
     < SafeMode  CallStack ="true"   />
    </ SharePoint >
   < system.web >
     < customErrors  mode ="Off"   />
     < compilation  debug ="true"   />
   </ system.web >
</ configuration >

2.然后附加w3wp进程,设置断点即可调试了。



本文转自生鱼片博客园博客,原文链接:http://www.cnblogs.com/carysun/archive/2008/04/19/applicationpage.html,如需转载请自行联系原作者

目录
相关文章
|
5天前
|
存储 人工智能 安全
AI 越智能,数据越危险?
阿里云提供AI全栈安全能力,为客户构建全链路数据保护体系,让企业敢用、能用、放心用
|
8天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
7天前
|
数据采集 人工智能 自然语言处理
3分钟采集134篇AI文章!深度解析如何通过云无影AgentBay实现25倍并发 + LlamaIndex智能推荐
结合阿里云无影 AgentBay 云端并发采集与 LlamaIndex 智能分析,3分钟高效抓取134篇 AI Agent 文章,实现 AI 推荐、智能问答与知识沉淀,打造从数据获取到价值提炼的完整闭环。
448 93
|
1天前
|
开发者
「玩透ESA」ESA启用和加速-ER在加速场景中的应用
本文介绍三种配置方法:通过“A鉴权”模板创建函数并设置触发器路由;在ESA上配置回源302跟随;以及自定义响应头。每步均配有详细截图指引,帮助开发者快速完成相关功能设置,提升服务安全性与灵活性。
287 2
|
7天前
|
SQL 人工智能 自然语言处理
Geo优化SOP标准化:于磊老师的“人性化Geo”体系如何助力企业获客提效46%
随着生成式AI的普及,Geo优化(Generative Engine Optimization)已成为企业获客的新战场。然而,缺乏标准化流程(Geo优化sop)导致优化效果参差不齐。本文将深入探讨Geo专家于磊老师提出的“人性化Geo”优化体系,并展示Geo优化sop标准化如何帮助企业实现获客效率提升46%的惊人效果,为企业在AI时代构建稳定的流量护城河。
409 156
Geo优化SOP标准化:于磊老师的“人性化Geo”体系如何助力企业获客提效46%
|
7天前
|
数据采集 缓存 数据可视化
Android 无侵入式数据采集:从手动埋点到字节码插桩的演进之路
本文深入探讨Android无侵入式埋点技术,通过AOP与字节码插桩(如ASM)实现数据采集自动化,彻底解耦业务代码与埋点逻辑。涵盖页面浏览、点击事件自动追踪及注解驱动的半自动化方案,提升数据质量与研发效率,助力团队迈向高效、稳定的智能化埋点体系。(238字)
316 158