从目录下载文件 [英] Download files from a directory

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

问题描述

有人可以指导我如何从目录分发和下载文件.我可以成功显示文件,但是我不知道要下载它.使用
进行文件分发

Can some1 guide me on how to dislay and download files from a dircetory.I can successfully display the file but i dnt have any idea about downloading it.For file dislay im using

string filepath = (@"~/NewFolder1/"+ "\\" + ddcollege.SelectedValue + "\\" + dddept.SelectedValue + "\\"
            + ddcategory.SelectedValue + "\\" + ddloctn.SelectedValue);

       // string[] subpath = "~/NewFolder1";
        string[] filePaths = Directory.GetFiles(Server.MapPath(filepath));

        //Response.Write(filePaths);

        List<ListItem> files = new List<ListItem>();

        foreach (string filePath in filePaths)
        {

            files.Add(new ListItem(Path.GetFileName(filePath), filePath));

        }

        gvdisplay.DataSource = files;

        gvdisplay.DataBind();*/

感谢

推荐答案

如果要提供文件链接,则需要提供可用于Web的链接.最简单的方法是执行server.mappath("//");然后将文件路径中的内容替换为网站的根URL.然后,只要IIS愿意提供它,您就可以呈现到它的链接.
If you want to provide links to files, you need to provide a link that is web ready. The easiest way is to do server.mappath("//"); and then replace that from the file path with the root URL of your site. Then you can render a link to it, so long as IIS is happy to serve it.


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

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