Search This Blog


Custom Application Page for the ECB Menu

We will now take the idea of creating a custom application page even further by examining one that displays information about a particular document in a document library. In our example, we will look at the application page named ApplicationPage4.aspx. We begin by creating a new CustomAction element. However, this CustomAction element does not add a menu item in the Site Actions menu. Instead, it is designed to add a new menu item to the ECB menu for each document within a document library. Examine the following XML fragment that defines a CustomAction.

Step 1.Open the project MyApplicationPages.csproj (created in")
Step 2. Add an aspx page "ApplicationPage4.aspx" under TEMPLATE/LAYOUTS/ folder of your project. and write the following code in your aspx page

<%@ Assembly Name="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="CustomApplicationPages, Version=, Culture=neutral, PublicKeyToken=d4e5777b16a5749f" %>

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master"
EnableViewState="false" EnableViewStateMac="false" %>

<%@ Register Tagprefix="SharePoint"
Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register Tagprefix="Utilities"
Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ID="Main" contentplaceholderid="PlaceHolderMain" runat="server">
<table border="1" cellpadding="5" cellspacing="0" style="width:100%; font-size: 9pt" >

<td>Site Title:</td>
<td><asp:Label ID="lblSiteTitle" runat="server" /> </td>
<td>Site URL:</td>
<td><asp:Label ID="lblSiteUrl" runat="server" /> </td>
<td>Document Library Title:</td>
<td><asp:Label ID="lblListTile" runat="server" /> </td>
<td>Document Library ID:</td>
<td><asp:Label ID="lblListID" runat="server" /> </td>
<td>Root Folder URL:</td>
<td><asp:Label ID="lblRootFolderUrl" runat="server" /> </td>
<td>Document Template Url:</td>
<td><asp:Label ID="lblDocumentTemplateUrl" runat="server" /> </td>

<td>Document Name:</td>
<td ><asp:Label ID="lblDocumentName" runat="server" /> </td>
<td>Document ID:</td>
<td ><asp:Label ID="lblDocumentID" runat="server" /> </td>

<td>Document URL:</td>
<td ><asp:Label ID="lblDocumentUrl" runat="server" /> </td>
<td>Document Author:</td>
<td ><asp:Label ID="lblFileAuthor" runat="server" /> </td>
<td>Document Size:</td>
<td ><asp:Label ID="lblFileSize" runat="server" /> </td>

<td>Document Last Modified:</td>
<td ><asp:Label ID="lblFileLastModified" runat="server" /> </td>
<td>Document Check Out Status:</td>
<td ><asp:Label ID="lblFileCheckOutStatus" runat="server" /> </td>



<asp:Content ID="PageTitle" contentplaceholderid="PlaceHolderPageTitle" runat="server">
Application Page 4

<asp:Content ID="PageTitleInTitleArea" contentplaceholderid="PlaceHolderPageTitleInTitleArea" runat="server">
Application Page 4 - Redirect from Document ECB Menu Item

Step 3.Create a class file ApplicationPage4.cs under the root folder of your project and write the following code
// redirect from ECB menu of document

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 ApplicationPage4 : 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) {

// get current site and web
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();


Step 4.Add the following code in your element.xml
<!-- Per Item Dropdown (ECB) Link -->
<CustomAction Id="CustomApplicationPage4"
Title="Application Page 4" >
<UrlAction Url="~site/_layouts/CustomApplicationPages/ApplicationPage4.aspx?ItemId={ItemId}&ListId={ListId}"/>

This CustomAction element is different than what you have seen before because it has a RegistrationType attribute that is assigned a value of List. It also is configured with a RegstrationID attribute that is assigned a value of 101. Note that 101 is a list type identifier that applies to all document libraries. You should also notice that the Location attribute has a value of EditControlBlock, which creates the effect of adding the menu item to the ECB menu of documents within a document library

Step5.Run the install.bat and activate your feature "My Custom Application Pages" in your sharepoint site.

Step6.Go to your document Library and click on the ECB menu,you will get an option "Application Page 4"

Step 7.Click on this ,you will get the following output

No comments: