我如何在我的网站中介绍下载过程 [英] how do i introduce the downloading process in my website

查看:72
本文介绍了我如何在我的网站中介绍下载过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在我的asp.net网站上介绍下载过程

how i can introduce the downloading process in my asp.net website

推荐答案

有两种基本方法:您可以直接提供指向该项目的链接(如完整网址),就像链接一样: http://www.codeproject.com/App_Themes/Std/Img/logo250x135.gif [ ^ ]
另一种方法更安全,并且需要使用ASPX控件:
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: http://www.codeproject.com/App_Themes/Std/Img/logo250x135.gif[^]
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))
        {
        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();
%>

通过查询字符串参数为该代码提供文件名,从数据库中检索它,并将其发送给用户.
上面有下载内容的页面只需要一个链接:

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>


这篇关于我如何在我的网站中介绍下载过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆