Click here to Skip to main content
13,090,426 members (45,268 online)
Rate this:
Please Sign up or sign in to vote.
See more:
how i can introduce the downloading process in my website
Posted 4-Oct-12 4:28am
gladiatron 4-Oct-12 10:47am
by coding it! :)
Sandip.Nascar 4-Oct-12 11:48am
Your question is not specific. Download is as simple as pointing in a href link. What exactly you want?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There are two basic ways: either you provide a direct link to the item (as a full URL) in the same way that this is a link:[^]
The other route is more secure, and requires the use of an ASPX control:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="wm5ftdl.aspx.cs" Inherits="wm5ftdl" %>
    // 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))
        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.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.WriteFile("wm5ftdata/" + fileName);
This code is given a file name via query string parameter, retrieves it from the database, and sends it to the user.
The page with the downloads on it just needs a link:
<a href=\"wm5ftdl.aspx?file=xxxx\" target=\"_blank\">Download human readable text</a>

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100