Need suggestion on URL Rewrite.....
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Need suggestion on URL Rewrite.....

  1. #1
    Join Date
    Aug 2010
    Posts
    3

    Question Need suggestion on URL Rewrite.....

    I have to do an module program which downloads pdf files in the client side. Currently, when users download the file, the url of the downloaded file is viewed by the user.

    Modification instructed:
    1. In the page where the file download is requested, the url of the downloaded file is viewed in the status bar of that web page. Modification is that the status bar should not display the url of the downloaded file. -- This had been corrected and the code has modified accordingly. It is done correctly only for the first page. Blinks how to process this for the second page..

    2. Currently, the call for the download page is given along with the filename of the user request. The filename is passed as the querystring. Modification needed is that the url should get rewritten as "~/download.aspx" instead of "~/download.aspx?".

    I came across using "urlrewriter". But don't know how to implement since i feel little confused with the code examples in net.

    I'm placing my code for ur assistance. I'm not using webconfig file also.

    old try pdf.aspx
    *************

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="old try pdf.aspx.cs" Inherits="old_try_pdf" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Try PDF - Download</title>
    <style>
    .link_text
    {
    font-family:Tahoma;
    font-size:10px;
    color:#1d5296;
    text-decoration:none;
    }

    .link_text A
    {
    font-family:Tahoma;
    font-size:11px;
    color:#1d5296;
    text-decoration:underline;
    }

    .link_text A:hover
    {
    color:#ff000c;
    text-decoration:underline;
    }

    .link_text A:active
    {
    color:#ff000c;
    text-decoration:underline;
    }

    .bullets
    {
    background-image:url(Bullet.gif);
    background-position:center;
    width:10px;
    height:10px;
    display:table-cell;
    vertical-align:top;
    background-repeat:no-repeat;
    }

    .display_cell
    {
    border:solid 1px #e6e7e8;
    display:table-cell;
    width:355px;
    }

    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td class='display_cell'>
    <asp:Panel runat="server" ID="pnl_pdf"></asp:Panel>
    </td>
    </tr>
    </table>

    </div>
    </form>
    </body>
    </html>


    old try pdf.aspx.cs
    ***************

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;

    public partial class old_try_pdf : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    Table tb_currency = new Table();
    tb_currency.Width = 355;
    TableRow tr_currency = new TableRow();
    TableCell tc_currency = new TableCell();
    Image img_currency = new Image();
    HyperLink hlk = new HyperLink();

    foreach (string fnames in Directory.GetFiles(@"~\Link 2 Download\pdf"))
    {
    string fname = null;

    tr_currency = new TableRow();

    tc_currency = new TableCell();
    tc_currency.CssClass = "bullets";
    tr_currency.Cells.Add(tc_currency);

    tc_currency = new TableCell();
    tc_currency.HorizontalAlign = HorizontalAlign.Left;
    tc_currency.CssClass = "link_text";
    hlk = new HyperLink();
    hlk.Target = "_blank";

    fname = Path.GetFileNameWithoutExtension(fnames);

    hlk.Text = fname;
    hlk.Attributes.Add("onMouseOver", "javascript:window.status=''; return true;");
    hlk.Attributes.Add("onMouseOut", "javascript:window.status=''; return true;");
    hlk.Attributes.Add("onClick", "javascript:window.status=''; return true;");
    hlk.NavigateUrl = "~/Old download_pdf.aspx?fn=" + fname;
    tc_currency.Controls.Add(hlk);
    tr_currency.Cells.Add(tc_currency);

    tb_currency.Rows.Add(tr_currency);
    }

    pnl_pdf.Controls.Clear();
    pnl_pdf.Controls.Add(tb_currency);

    }
    }


    Old download_pdf.aspx
    *******************

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Old download_pdf.aspx.cs" Inherits="Old_download_pdf" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
    </body>
    </html>




    Old download_pdf.aspx.cs
    *********************

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net;
    using System.IO;


    public partial class Old_download_pdf : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    // Create a message string
    string strMessage = "Wait.... File is downloading....";
    // Register startup script to show a message in status bar
    this.RegisterStartupScript("SetStatusText", "<script>window.status='" + strMessage + "';</script>");

    if (Request.QueryString.Count > 0)
    {
    string fn = Request.QueryString.Get(0).ToString();

    string spath = @"~\pdf\" + fn + ".pdf";
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    //Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=my_test.pdf");

    Response.TransmitFile(spath);
    Response.End();
    }

    }
    }



    Even using register startup variable, in Old_download_pdf.aspx, it is showing the downloaded file url path in status bar of the page Old_download_pdf.aspx. Also we have to rewrite the url from "~/Old download_pdf.aspx?fn=" as simply "~/Old download_pdf.aspx".

    When i tried using a hidden variable, i failed in setting the value of the hidden field during the click event of the dynamically creating hyperlink control.


    How to complete this? Thanks in advance.

    Regards,
    M.Sworna Vidhya

  2. #2
    Join Date
    Dec 2007
    Posts
    234

    Re: Need suggestion on URL Rewrite.....

    the form action should be POST ... the default is GET ...

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

  3. #3
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    Re: Need suggestion on URL Rewrite.....

    Code:
     Please use the [ code ]  tags in the future, makes the code a bit easier to read.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center