Tuesday, September 9, 2008

Custom Application Page for ListID issue

You want to provide a link to a particular System Application Page, but all the application pages accepts parameter in form of some ID which is not unique in different environments.

Custom Application page that accepts the ListName and page you want to get redirected to. The new custom page will internally gets the correct ListID and then will re-direct to the correct Application page.


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

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<script runat="server">
protected override void OnLoad(EventArgs e)
SPWeb site = this.Web;

Guid listID = default(System.Guid);

string listName = Request.QueryString["List"];
string pageName = Request.QueryString["Page"];

if (listName != null && pageName != null)
foreach (SPList list in site.Lists)
if (list.Title.ToLower() == listName.ToLower())
listID = list.ID;

Response.Redirect(this.Web.Url + @"/_layouts/" + pageName + ".aspx?List=" + listID);

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
Redirection Page - Please pass the proper Request Query Parameters to get the redirection to work.</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">Redirection Page</asp:Content>

<asp:Content ID="PageTitleInTitleArea" runat="server" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea">Redirection Page</asp:Content>

Now you can call this Redirect page as

and you will be redirected to the List Settings ( listedit.aspx ) of the Tasks list.