在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,下面是项目的结构:

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演示的是在一个列表库的列表项的编辑菜单里出现一个链接,统计该列表的信息,如下图:

要添加此菜单须在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();
      }
    }
    
  }
}

结果如下图:

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

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);
      }
    } 
  }
}

效果如下图:

如何调试:
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,如需转载请自行联系原作者

MOSS点滴(2):自定义Application Page相关推荐

  1. 为SharePoint 2010创建Application Page

    如果不了解什么是Application Page,可以参考我以前写过的这篇文章.SharePoint 2010的页面模型没有太多的变化,基本和2007保持一致.对于开发人员而言,为SharePoint ...

  2. SharePoint基础之九- Site Page与Application Page

    在一个WSS站点中的某些页面, 比如说首页(default.aspx), 支持用户使用SharePoint Designer这样的工具进行定制化(customization). 支持定制化的页面叫做s ...

  3. SharePoint Application Page启用匿名访问

    现在的项目需要使用sharepoint application page来展示图片影像,并让其它应用系统匿名访问,经过一番认真研究,主要有下面的步骤: 1. 在web applicaiton leve ...

  4. Android 自定义Application

    在android中 自定义Application 常用的作用是 1 保存在程序运行中的全局变量 实例: public class GlobalApp extends Application{ priv ...

  5. 在MOSS 2007中自定义DataView Webpart的数据显示样式

    熟悉MOSS开发的人都知道MOSS中提供了一种用来进行数据展示的Webpart,它可以让开发人员在不需要编写一行代码的基础上轻松地从List中取出数据,并以一定的格式将数据显示在页面上,这就是MOSS ...

  6. MOSS点滴(1):如何开发和部署feature

    Features 是MOSS 2007以开箱即用的一套新功能,Features 存储在SharePoint服务器的如下路径下:C:\Program Files\Common Files\Microso ...

  7. MOSS中如何自定义WebService

    MOSS中已经提供的webservice都放在虚拟目录_vti_bin中,对应的物理目录为c:\Program Files\Common Files\Microsoft Shared\Web Serv ...

  8. Android自定义Application的作用

    1.保存在程序运行中的全局变量 public class GlobalApp extends Application{private UserData udata ; public UserData ...

  9. android 6.0 自定义application,Android6.0之App中的资源管理对象创建

    Android与资源管理相关的类Resouces和AssetManager很有必要清楚他们的创建过程. 与资源查找与加载操作相关的类 资源查找与加载主要是靠Android资源管理框架来完成的,而And ...

最新文章

  1. 线程间的通信 共享数据安全问题
  2. Elasticsearch 7.0中引入的新集群协调子系统如何使用?
  3. IE8下Jquery获取select选中的值的问题
  4. uml+oopc嵌入式c语言开发精讲_当前火爆的嵌入式领域,为什么选择C语言作为开发语言?了解一下...
  5. python对律师的作用_想知道在大家眼中律师的作用是什么
  6. arcgis导入excel数据_ArcGIS批量导入数据
  7. C语言 指针自增自减加减运算 p++ p+i
  8. django后台多页面分页逻辑python代码
  9. html有序列表和无序列表互相嵌套,关于列表的嵌套,下列说法正确的是( )。 答案:无序列表和有序列表可以相互嵌套与 之间相当于一个容器,可以嵌套无序列表、有序列表等网页元素...
  10. 5月25号GE一面经历
  11. 写给 Python 开发者的 10 条机器学习建议
  12. 【Computer Organization笔记11】多周期CPU
  13. mac好用的图片转文字,ocr文字识别工具:Text Scanner
  14. 【洛谷】P1216数字三角形
  15. 使用ES6,Pt更好JavaScript。 II:深入学习课堂
  16. 分布式CAP是什么?
  17. 如何高效开展测试用例评审?附用例评审检查清单及用例评审报告模板
  18. mac 苹果电脑恢复 Recovery HD;进不去恢复模式;
  19. php cms下载地址,下载phpcms详细步骤
  20. 字节跳动,野心十足,十年有可能打败腾讯成为第二个互联网巨头吗?

热门文章

  1. Linux学习:第二章-Linux安装
  2. 学习笔记13-C语言-字符串函数、缓冲区
  3. 终于,我读懂了所有Java集合——set篇
  4. 《Head First设计模式》第九章(1)迭代器模式
  5. 由旅行商问题认识何为状态压缩
  6. UNIX(多线程):26---悲观锁和乐观锁
  7. 《剑指Offer》37:序列化二叉树
  8. Linux加密框架 crypto算法模板 以及HMAC算法模板实例
  9. 安卓 原生okhttp使用get与post获取网络数据
  10. 广州交警发布科目三电子路考操作要点