从服务器到本地主机下载的文件夹 [英] download a folder from server to local host

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

问题描述

我有一个code键downolad存储在特定位置处的服务器上的一个特定的文件...

I have a code to downolad a particular file that is stored at a particular location on the server...

例如,我有在C文件untitled.bmp:我的服务器的驱动器,我使用的特定code下载这我的本地...

for example i have a file untitled.bmp in the C: drive of my server and i download this to my localhost using the particular code...

  protected void Button1_Click(object sender, EventArgs e)
    {
         string filepath = (@"C:\untitled.bmp");



        // Create New instance of FileInfo class to get the properties of the file being downloaded
        FileInfo myfile = new FileInfo(filepath);

        // Checking if file exists
        if (myfile.Exists)
        {
            // Clear the content of the response
            Response.ClearContent();

            // Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
            Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);

            // Add the file size into the response header
            Response.AddHeader("Content-Length", myfile.Length.ToString());

            // Set the ContentType
            Response.ContentType = ReturnExtension(myfile.Extension.ToLower());

            // Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
            Response.TransmitFile(myfile.FullName);

            // End the response
            Response.End();
        }
    }


    private string ReturnExtension(string fileExtension)
    {
        switch (fileExtension)
        {
            case ".htm":
            case ".html":
            case ".log":
                return "text/HTML";
            case ".txt":
                return "text/plain";
            case ".doc":
                return "application/ms-word";
            case ".tiff":
            case ".tif":
                return "image/tiff";
            case ".asf":
                return "video/x-ms-asf";
            case ".avi":
                return "video/avi";
            case ".zip":
                return "application/zip";
            case ".xls":
            case ".csv":
                return "application/vnd.ms-excel";
            case ".gif":
                return "image/gif";
            case ".jpg":
            case "jpeg":
                return "image/jpeg";
            case ".bmp":
                return "image/bmp";
            case ".wav":
                return "audio/wav";
            case ".mp3":
                return "audio/mpeg3";
            case ".mpg":
            case "mpeg":
                return "video/mpeg";
            case ".rtf":
                return "application/rtf";
            case ".asp":
                return "text/asp";
            case ".pdf":
                return "application/pdf";
            case ".fdf":
                return "application/vnd.fdf";
            case ".ppt":
                return "application/mspowerpoint";
            case ".dwg":
                return "image/vnd.dwg";
            case ".msg":
                return "application/msoutlook";
            case ".xml":
            case ".sdxl":
                return "application/xml";
            case ".xdp":
                return "application/vnd.adobe.xdp+xml";
            default:
                return "application/octet-stream";
        }
    }

我现在的问题是怎样下载一个文件夹,在它的多个文件..有没有办法?

now my problem is how do i download a folder with multiple files in it.. is there a way???

例如我有一个文件夹名为C恢复:驱动器,其中包含两个文件untitled.bmp和test.txt的...

for example i have a folder named recovery in C: drive which contains two files untitled.bmp and test.txt...

感谢...

我需要做的这一点没有拉拉链......请提出一个方法...

I need to do this without zipping... please suggest a way...

推荐答案

有关多个文件,你需要将其打包一起作为,例如,一个ZIP文件。

For multiple files, you'll need to pack them together as, for instance, a ZIP file.

<一个href=\"http://highoncoding.com/Articles/597_Downloading_Multiple_Files_as_a_Zip_File_Using_GridView_and_SharpZipLib.aspx\"相对=nofollow>下载多个文件作为一个Zip文件使用GridView和SharpZipLib

这篇关于从服务器到本地主机下载的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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