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

目录
相关文章
|
1月前
在 CRM WebClient UI Attachment 区域,创建支持 Web Service 的 Word 文档
在 CRM WebClient UI Attachment 区域,创建支持 Web Service 的 Word 文档
21 0
|
5月前
|
Web App开发 存储 安全
大师学SwiftUI第17章Part1 - Web内容访问及自定义Safari视图控制器
App可以让用户访问网页,但实现的方式有不止一种。我们可以让用户通过链接在浏览器中打开文档、在应用界面中内嵌一个预定义的浏览器或是在后台下载并处理数据。
46 0
|
6月前
|
数据可视化 Android开发 开发者
SAP Fiori Tools Application Modeler Page Map 标题的数据源
SAP Fiori Tools Application Modeler Page Map 标题的数据源
35 0
|
6月前
|
存储 数据可视化 定位技术
关于 SAP Fiori Tools Application Modeler Page Map 功能的 app.json
关于 SAP Fiori Tools Application Modeler Page Map 功能的 app.json
31 0
|
7月前
|
机器人 SEO
SAP 电商云 Spartacus UI 根据 url 设置 site context 的具体例子
SAP 电商云 Spartacus UI 根据 url 设置 site context 的具体例子
54 0
|
中间件 iOS开发
Axure实战12:创建一个GuidePage引导页示例
Axure实战12:创建一个GuidePage引导页示例
264 0
Axure实战12:创建一个GuidePage引导页示例
|
数据采集 JSON 前端开发
单页面 Web 应用(Single Page Application,SPA)的工作原理介绍
单页面 Web 应用(Single Page Application,SPA)的工作原理介绍
243 0
单页面 Web 应用(Single Page Application,SPA)的工作原理介绍
把自定义url配置到SAP Fiori Launchpad上打开
把自定义url配置到SAP Fiori Launchpad上打开
把自定义url配置到SAP Fiori Launchpad上打开
如何在 SAP Spartacus 里添加自定义页面 - Custom Page
网友提问 Add a custom page to Spartacus I would like to add a custom sub page (http://localhost:4200/image-upload) to spartacus. The Header and Footer should be the same. Just the content should be an upload form. 三个步骤 Add a new content page in CMS with page label /image-upload (with the leading slash
如何在 SAP Spartacus 里添加自定义页面 - Custom Page
SAP Spartacus content page url的硬编码列表 - Page Label
SAP Spartacus content page url的硬编码列表 - Page Label
92 0