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

目录
相关文章
|
机器学习/深度学习 数据采集 传感器
3DAT助力冬奥开幕式及赛前训练:这究竟是什么「神秘黑科技」?
北京冬奥虽已收官,但有一幕却让冰雪运动的爱好者们久久难忘,那就是 2 月 12 日晚,中国队凭借 34 秒 32 的成绩获得北京冬奥会速度滑冰男子 500 米比赛金牌,并刷新了该项目奥运纪录的那一幕。
182 0
3DAT助力冬奥开幕式及赛前训练:这究竟是什么「神秘黑科技」?
|
搜索推荐 算法 小程序
BB买买买,微博怎么办?
BB买买买,微博怎么办?
171 0
BB买买买,微博怎么办?
|
Unix 关系型数据库 Java
|
3天前
|
人工智能 自然语言处理 Shell
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
仅用3分钟,百炼调用满血版Deepseek-r1 API,享受百万免费Token。阿里云提供零门槛、快速部署的解决方案,支持云控制台和Cloud Shell两种方式,操作简便。Deepseek-r1满血版在推理能力上表现出色,尤其擅长数学、代码和自然语言处理任务,使用过程中无卡顿,体验丝滑。结合Chatbox工具,用户可轻松掌控模型,提升工作效率。阿里云大模型服务平台百炼不仅速度快,还确保数据安全,值得信赖。
157353 24
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
|
5天前
|
人工智能 API 网络安全
用DeepSeek,就在阿里云!四种方式助您快速使用 DeepSeek-R1 满血版!更有内部实战指导!
DeepSeek自发布以来,凭借卓越的技术性能和开源策略迅速吸引了全球关注。DeepSeek-R1作为系列中的佼佼者,在多个基准测试中超越现有顶尖模型,展现了强大的推理能力。然而,由于其爆火及受到黑客攻击,官网使用受限,影响用户体验。为解决这一问题,阿里云提供了多种解决方案。
17001 37
|
13天前
|
机器学习/深度学习 人工智能 自然语言处理
PAI Model Gallery 支持云上一键部署 DeepSeek-V3、DeepSeek-R1 系列模型
DeepSeek 系列模型以其卓越性能在全球范围内备受瞩目,多次评测中表现优异,性能接近甚至超越国际顶尖闭源模型(如OpenAI的GPT-4、Claude-3.5-Sonnet等)。企业用户和开发者可使用 PAI 平台一键部署 DeepSeek 系列模型,实现 DeepSeek 系列模型与现有业务的高效融合。
|
5天前
|
并行计算 PyTorch 算法框架/工具
本地部署DeepSeek模型
要在本地部署DeepSeek模型,需准备Linux(推荐Ubuntu 20.04+)或兼容的Windows/macOS环境,配备NVIDIA GPU(建议RTX 3060+)。安装Python 3.8+、PyTorch/TensorFlow等依赖,并通过官方渠道下载模型文件。配置模型后,编写推理脚本进行测试,可选使用FastAPI服务化部署或Docker容器化。注意资源监控和许可协议。
1311 8
|
13天前
|
人工智能 搜索推荐 Docker
手把手教你使用 Ollama 和 LobeChat 快速本地部署 DeepSeek R1 模型,创建个性化 AI 助手
DeepSeek R1 + LobeChat + Ollama:快速本地部署模型,创建个性化 AI 助手
3416 117
手把手教你使用 Ollama 和 LobeChat 快速本地部署 DeepSeek R1 模型,创建个性化 AI 助手
|
8天前
|
人工智能 自然语言处理 API
DeepSeek全尺寸模型上线阿里云百炼!
阿里云百炼平台近日上线了DeepSeek-V3、DeepSeek-R1及其蒸馏版本等六款全尺寸AI模型,参数量达671B,提供高达100万免费tokens。这些模型在数学、代码、自然语言推理等任务上表现出色,支持灵活调用和经济高效的解决方案,助力开发者和企业加速创新与数字化转型。示例代码展示了如何通过API使用DeepSeek-R1模型进行推理,用户可轻松获取思考过程和最终答案。
|
5天前
|
人工智能 自然语言处理 程序员
如何在通义灵码里用上DeepSeek-V3 和 DeepSeek-R1 满血版671B模型?
除了 AI 程序员的重磅上线外,近期通义灵码能力再升级全新上线模型选择功能,目前已经支持 Qwen2.5、DeepSeek-V3 和 R1系列模型,用户可以在 VSCode 和 JetBrains 里搜索并下载最新通义灵码插件,在输入框里选择模型,即可轻松切换模型。
934 14

热门文章

最新文章