在我的网站上使用下载功能 [英] Use of download ability in my web site

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

问题描述

在我的网站上使用下载功能

我有网站.我想将此功能应用于我的网站,以便从我的网站下载zip文件.
我知道如何上传文件.但是我不知道要下载的源代码. (通过c#)
非常感谢

Use of download ability in my web site
Hi
I have web site . I wants to put this ability to my site for download a zip file from my site.
I know how upload files. But I don’t know the source code for download. (by c#)
Thanks very much

推荐答案

以下是使用ASP .NET下载文件的示例代码.
Here is the sample code to download a file using ASP .NET

try
{
   System.String filename = "myFile.txt";

   // set the http content type to "APPLICATION/OCTET-STREAM
   Response.ContentType = "APPLICATION/OCTET-STREAM";
   
   // initialize the http content-disposition header to
   // indicate a file attachment with the default filename
   // "myFile.txt"
   System.String disHeader = "Attachment; Filename=\"" + filename +
      "\"";
   Response.AppendHeader("Content-Disposition", disHeader);

   // transfer the file byte-by-byte to the response object
   System.IO.FileInfo fileToDownload = new
      System.IO.FileInfo("C:\\download\\myFile.txt");
   Response.Flush();
   Response.WriteFile(fileToDownload.FullName);}
catch (System.Exception e)
// file IO errors
{
   SupportClass.WriteStackTrace(e, Console.Error);
}


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

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