ShowLinkAs Page - ASP.NET


The following code depends on the ApplicationRootUrl function (found here) placed within a class called Helper.


Create a new ASPX page called GetPage.aspx. It doesn't matter whether or not it has an associated master page.

GetPage.aspx Code-Behind


Imports System.Diagnostics

Namespace SalesMarketing
    Partial Class GetPage
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim strRequestedURL As String = ""

            If Not Request("RP") Is Nothing Then

                strRequestedURL = Helper.ApplicationRootUrl
                strRequestedURL &= Request("RP")
                strRequestedURL &= Request("RF")

            End If


        End Sub
        Private Sub WriteLog(ByVal strRequestedUrl As String)

            'Dim intModuleId As Int16 = 0
            'Dim lngSearchLogId As Long = 0
            'Dim strFromURL As String = ""

            ''-- Inits -----------------------------------------------------------------------------
            'If Not Request("MId") Is Nothing Then
            '    If IsNumeric(Request("MId")) Then
            '        intModuleId = CType(Request("MId"), Int16)
            '    End If
            'End If
            'If Not Request("SLId") Is Nothing Then
            '    If IsNumeric(Request("SLId")) Then
            '        lngSearchLogId = CType(Request("SLId"), Long)
            '    End If
            'End If
            'If Request.ServerVariables("HTTP_REFERER") <> "" Then
            '    strFromURL = Request.ServerVariables("HTTP_REFERER") ' RequestFromPage
            'End If

            'Dim currUser As String
            'currUser = HttpContext.Current.Request.ServerVariables("AUTH_USER")
            'currUser = Mid(currUser, InStr(currUser, "\") + 1)

            'Dim strIsAuthor As String = CType(Me.Master, Site).IsAuthorByModule(intModuleId)

            ''-- Make Database Call ----------------------------------------------------------------
            'Dim cl As New SalesMarketing.BusinessLogicLayer.ClickLog

            'cl.Add(intModuleId, lngSearchLogId, currUser, strFromURL, strRequestedURL, Now(), _
            '            strIsAuthor)
            'cl = Nothing

        End Sub

    End Class

End Namespace




    <add key="LinkAsPage" value="GetPage.aspx"/>

Image Files

Save the following images into your /images folder



Create a new ASPX page called ShowLinkAs.aspx, having NO master page and with the following content.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ShowLinkAs.aspx.vb" 
    Inherits="SalesMarketing.ShowLinkAs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="" >
<head runat="server">
    <title>Link As</title>
    <link href="Styles.css" rel="stylesheet" type="text/css" />
    <form id="form1" runat="server">
    <table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
        <td align="center" class="lbl-header">Link Document/URL As</td>
        <td class="standard-instruction">
        <img src="./images/bullet.gif" />&nbsp;Please copy the below text to 
            link the document/url.<br />
        <td align="center">
            <br />&nbsp;<br />
            <asp:TextBox ID="txtLA" runat="server" Columns="100" Rows="5" Width="600" Height="100" 
                 Wrap="true" CssClass="standard-text"></asp:TextBox>
            <br />&nbsp;<br />
            <input type="button" value="Close" onclick="javascript:window.close();" />
            <br />

ShowLinkAs.aspx Code-Behind


Namespace SalesMarketing
    Partial Class ShowLinkAs
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            txtLA.Text = Helper.ApplicationRootUrl
            txtLA.Text &= ConfigurationManager.AppSettings("LinkAsPage") & "?MId="
            txtLA.Text &= Request("MId")
            txtLA.Text &= "&RP=" & Request("RP")
            txtLA.Text &= "&RF=" & Server.UrlEncode(Request("RF"))
        End Sub
    End Class
End Namespace



Master Page

<script language="javascript">
. . .
function showLinkAs(iVal)
    var vURL = "ShowLinkAs.aspx" + iVal;
    if (window.showModelessDialog)
        sList = showModalDialog(vURL, window, "dialogHeight:250px; dialogWidth:750px; edge:sunken; center:yes; help:no; status:no; scroll:no; resizable:no;");
        alert("This method is only supported by Internet Explorer 4 and above.");
. . .

Content Page

Here's a sample helper function that builds the link suitable for inclusion on an ASPX or HTML page. The QueryString parameters are as follows.


Private Function BuildLink(ByVal id As Integer, ByVal file As String) As String

    '-- Inits ---------------------------------------------------------------------------------
    ' TODO: Adjust the queryString template appropriate to your implementation
    Dim queryString As String = "?RP=uploads/TD/{id}/&RF={file}"

    Dim imageLink As String = "<a href='javascript:showLinkAs(""{queryString}"")'>"
    imageLink &= "<img src=""./images/link.jpg"" border=none /></a>"

    Dim result As String = "<a target='_blank' href='GetPage.aspx{queryString}&SLId=0'>"
    result &= "{file}</a>&nbsp;&nbsp;&nbsp;{imageLink}&nbsp;&nbsp;&nbsp;"

    file = Server.UrlEncode(file)

    '-- "Fill In" the templates ---------------------------------------------------------------
    queryString = queryString.Replace("{id}", id)
    queryString = queryString.Replace("{file}", file)
    imageLink = imageLink.Replace("{queryString}", queryString)
    result = result.Replace("{queryString}", queryString)
    result = result.Replace("{file}", file)
    result = result.Replace("{imageLink}", imageLink)

    '-- Clean Up ------------------------------------------------------------------------------
    Return result

End Function