下载我以前上传的文件 [英] download a file what i have previously uploaded

查看:79
本文介绍了下载我以前上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经选择了一个下拉列表来选择要下载的文件
并与数据库绑定,我也可以通过一个按钮进行下载

我在button_click中编写了以下代码以下载

i have taken one dropdownlist for select file what u want to download
and also bind with database and i have take one button also for downloading

i have write following a code in button_click for downloading

string fname = DropDownList1.SelectedItem.Text;
    string filepath = Server.MapPath(@"~\Upload\" + fname);
    FileInfo fi = new FileInfo(filepath);
    if (fi.Exists )
    {
        Response.ClearContent();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + fname);
        Response.AddHeader("Content-Length", fi.Length.ToString());
        Response.ContentType = "application";
        Response.TransmitFile(fi.FullName);
        Response.End();
    }


它仅适用于dropdpwnlist item [0]元素,只能下载


但不适用于dropdownlist


it''s working only for dropdpwnlist item[0] element can only downloaded


but not working for remaining items in dropdownlist

推荐答案

string fname = DropDownList1.SelectedItem.Text;
string searverdir = Request.PhysicalApplicationPath.ToString() + fname;          
        string[] str = new string[2];
        str = searverdir.Split('.');
        Response.ClearHeaders();
        Response.ClearContent();
        Response.ContentType = "application/" + str[1].ToString() + "";
        Response.AddHeader("content-disposition", "attachment; fname= " + searverdir + "");
        Response.WriteFile(searverdir);
        Response.Flush();
        Response.Close();




试试这个.

问候,
Anilkumar.D




Try this.

Regards,
Anilkumar.D


检查这些链接
http: //www.west-wind.com/weblog/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET [ http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog [ ^ ]

如何下载和上传文件 [ ^ ]
Check these links
http://www.west-wind.com/weblog/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET[^]

http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog[^]

how to download and upload a file[^]


这篇关于下载我以前上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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