Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
Hi, Every ...
I want to find out can we make several temp addresses at host by different times and different addresses to a same file?! As Download link?

please answer me! is?

What I have tried:

I haven't anything to try! please be kind
Posted
Updated 2-Oct-19 23:29pm
v2
Comments
Maciej Los 3-Oct-19 2:08am    
?!?
Afzaal Ahmad Zeeshan 3-Oct-19 2:38am    
I think you can simply route all the traffic to a particular file on the server. No?

1 solution

There are a load of ways to do this, starting off by linking to a page that doesn't exist on your system: "mydomain.com/downloads/F543210987" and handling the 404 error. Get the filename, translate that to the actual file (probably via a DB) and serve that up as a download item.
Then there are ASHX pages which do the same thing but don't need the DB.
Or a Download.aspx file that takes a query string - I use this one.
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileTransferDownload.aspx.cs" Inherits="FileTransferDownload" %>

<%  
    // Send a download file to the client given the filename.    
    string guid = Request.QueryString["file"];
    string fileName = "ERROR";
    byte[] data = new byte[] { 0, 0, 0, 0 };
    string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DownloadDatabase"].ConnectionString;
    using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strCon))
        {
        con.Open();
        string strcmd = "SELECT [iD] ,cn.[fileName],[description] ,[dataContent] ,[version] " +
                        "FROM dlContent cn " +

                        "WHERE cn.iD=@ID";
        using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strcmd, con))
            {
            cmd.Parameters.AddWithValue("@ID", guid);
            using (System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader())
                {
                if (r.Read())
                    {
                    fileName = (string) r["filename"];
                    data = (byte[]) r["dataContent"];
                    }
                }
            }
        }
    Response.Clear();
    Response.AddHeader("Cache-Control", "no-cache, must-revalidate, post-check=0, pre-check=0");
    Response.AddHeader("Pragma", "no-cache");
    Response.AddHeader("Content-Description", "File Download");
    Response.AddHeader("Content-Type", "application/force-download");
    Response.AddHeader("Content-Transfer-Encoding", "binary\n");
    Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
    Response.BinaryWrite(data);
    //Response.WriteFile("wm5ftdata/" + fileName);
    Response.End();  
%>

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class FileTransferDownload : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
 
Share this answer
 
v2
Comments
Maciej Los 3-Oct-19 5:00am    
Hmmm...
"load of ways" Shouldn't be "lot of ways"?
Cheers!
Maciej
OriginalGriff 3-Oct-19 5:17am    
"A load of ways" or "a lot of ways" would have been fine, as would "loads of ways" or "lots of ways".

But no, you are right: "load of ways" on it's own was not good English. Fixed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900