文件管理 · 2022年7月25日

aspnet多文件下载|aspnet下载文件

1. asp.net中多个文件打包下载

有专用的打包工具也可以用相当傻瓜化的VS2003 或2005或更高注意:为了保护你的版权,请你手动删除CS文件和resx文件或者使用它自带的筛选器自动筛选这些东西都属于项目实施和部署的范畴,你可以找些文档看下

2. 一个关于asp.net(c#)下载文件的问题

如果是text格式的话,一般IE默认是直接把文件打开

3. asp.net网站如何实现 下载多个文件 或者下载某个文件夹,像bt那样的下载后文件夹里包含所需的多个文件

1.“不要告诉我 直接把文件夹压缩后 再下载 这个谁都知道”如果我告诉你,把文件夹放到服务器上,然后用代码将文件夹压缩之后给客户下载RAR文件,这个你已经知道了?2.你能不能遍历要下载的文件夹里的文件,然后做成超链接让人家下载呢?

4. asp.net下载文件

这样是不行的,要把它转化为输出流才能弹出那个保存文件的对话框。看我写的文章http://blog.csdn.net/gdjlc/archive/2009/10/27/4733266.aspx(ASP.NET 文件下载)上面稍微改下就可以用了,string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName;注意s_fileName的路径要正确,假如当前服务器目录是Web,则数据库表字段存的路径要为“txt\60种时间格式.txt”,这样s_path在下载时才能完整的变为E:\ZhongShe。。。

5. asp.net文件下载,谢谢!

用代码实现下载。 string sLocalPath=“”;// 文件路径 System.IO.FileInfo DownloadFile = new System.IO.FileInfo(sLocalPath); Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(lnk.ToolTip, System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); Response.WriteFile(DownloadFile.FullName); Response.Flush(); Response.End();

6. c#.net 多个文件下载,我是把他们先压缩成rar 然后下载的,怎么做到下载完成后删除此rar呢

根据压缩成的rar文件的大小。即文件的字节数量。判断接受到的字节量是否和rar压缩文件大小一致。一致则下载完成。解压。删除。

7. asp.net实现文件下载

这是一个网站下载的一段代码:public partial class download : System.Web.UI.Page{ BaseClass BaseClass1 = new BaseClass(); protected void Page_Load(object sender, EventArgs e) { Page.EnableViewState = false; /* 微软为Response对象提供了一个新的方法TransmitFile来解决使用Response.BinaryWrite 下载超过400mb的文件时导致Aspnet_wp.exe进程回收而无法成功下载的问题。 代码如下: */ if (!IsPostBack) { //从数据库取得文件名 string sqlStr = "select * from sourceDownLoad where sId=" + Request.QueryString["id"]; DataTable dt = BaseClass1.ReadTable(sqlStr); DataTableReader reader = dt.CreateDataReader(); string sourceName = (string)dt.Rows[0].ItemArray[1]; sourceName.Trim();//消除空格 int index= sourceName.LastIndexOf("."); string extend = sourceName.Substring(index+1);//扩展名 string fullPath = "~/sourceDLoad/" + sourceName; fullPath = Server.MapPath(fullPath); //读出该资源的下载次数 int downloadtimes = 0; if (reader.Read())// { downloadtimes=reader.GetInt32(4); } Page.Response.Clear(); bool success = ResponseFile(Page.Request, Page.Response, sourceName ,fullPath , 1024000); if (!success) Response.Write("下载文件出错!"); else { //记录下载次数 downloadtimes++; sqlStr = "update sourceDownLoad set downloadCounts=" + downloadtimes + " where sId=" + Request.QueryString["id"]; BaseClass1.execsql(sqlStr); } Page.Response.End(); } } public static bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullPath, long _speed) { try { FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(myFile); try { _Response.AddHeader("Accept-Ranges", "bytes"); _Response.Buffer = false;//不缓冲 long fileLength = myFile.Length; long startBytes = 0; double pack = 10240; //10K bytes int sleep = 200; //每秒5次 即5*10K bytes每秒 int sleep = (int)Math.Floor(1000 * pack / _speed) + 1; if (_Request.Headers["Range"] != null) { _Response.StatusCode = 206; string[] range = _Request.Headers["Range"].Split(new char[] ); startBytes = Convert.ToInt64(range[1]); } _Response.AddHeader("Content-Length", (fileLength – startBytes).ToString()); if (startBytes != 0) { //Response.AddHeader("Content-Range", string.Format(" bytes -/", startBytes, fileLength-1, fileLength)); } _Response.AddHeader("Connection", "Keep-Alive"); _Response.ContentType = "application/octet-stream"; _Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8)); br.BaseStream.Seek(startBytes, SeekOrigin.Begin); int maxCount = (int)Math.Floor((fileLength – startBytes) / pack) + 1; for (int i = 0; i < maxCount; i++) { if (_Response.IsClientConnected) { _Response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString()))); Thread.Sleep(sleep); } else { i = maxCount; } } } catch { return false; } finally { br.Close(); myFile.Close(); } } catch { return false; } return true; } //这样就实现了文件下载时,不管是什么格式的文件,都能够弹出打开/保存窗口.}9月

8. asp.net 下载文件

貌似比较麻烦除非不让弹出保存文件的默认对话框自己用openFileDialog什么之类的控件来获取可能可行

9. 在Asp.Net中我要一次下载多个文件如何实现

也就是通过循环来做咯

10. 怎样在asp.net中 实现多个文件打包下载

先下载 ICSharpCode.SharpZipLib.dll public string cutStr = ""; public void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize) { //如果文件没有找到则报错。 if (!System.IO.File.Exists(FileToZip)) { throw new System.IO.FileNotFoundException("The specified file " + FileToZip + " could not be found. Zipping aborderd"); } System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile); ZipOutputStream ZipStream = new ZipOutputStream(ZipFile); ZipEntry ZipEntry = new ZipEntry("ZippedFile"); ZipStream.PutNextEntry(ZipEntry); ZipStream.SetLevel(CompressionLevel); byte[] buffer = new byte[BlockSize]; System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length); ZipStream.Write(buffer, 0, size); try { while (size < StreamToZip.Length) { int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length); ZipStream.Write(buffer, 0, sizeRead); size += sizeRead; } } catch (System.Exception ex) { throw ex; } ZipStream.Finish(); ZipStream.Close(); StreamToZip.Close(); } //Get all DirectoryInfo private void direct(DirectoryInfo di, ref ZipOutputStream s, Crc32 crc) { //DirectoryInfo di = new DirectoryInfo(filenames); DirectoryInfo[] dirs = di.GetDirectories("*"); //遍历目录下面的所有的子目录 foreach (DirectoryInfo dirNext in dirs) { //将该目录下的所有文件添加到 ZipOutputStream s 压缩流里面 FileInfo[] a = dirNext.GetFiles(); this.writeStream(ref s, a, crc); //递归调用直到把所有的目录遍历完成 direct(dirNext, ref s, crc); } } private void writeStream(ref ZipOutputStream s, FileInfo[] a, Crc32 crc) { foreach (FileInfo fi in a) { //string fifn = fi.FullName; FileStream fs = fi.OpenRead(); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); //ZipEntry entry = new ZipEntry(file); Path.GetFileName(file); string file = fi.FullName; file = file.Replace(cutStr, ""); ZipEntry entry = new ZipEntry(file); entry.DateTime = DateTime.Now; // set Size and the crc, because the information // about the size and crc should be stored in the header // if it is not set it is automatically written in the footer. // (in this case size == crc == -1 in the header) // Some ZIP programs have problems with zip files that don't store // the size and crc in the header. entry.Size = fs.Length; fs.Close(); crc.Reset(); crc.Update(buffer); entry.Crc = crc.Value; s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); } } /// <summary> /// 压缩指定目录下指定文件(包括子目录下的文件) /// </summary> /// <param name="zippath">args[0]为你要压缩的目录所在的路径 /// 例如:D:\\temp\\ (注意temp 后面加 \\ 但是你写程序的时候怎么修改都可以)</param> /// <param name="zipfilename">args[1]为压缩后的文件名及其路径 /// 例如:D:\\temp.zip</param> /// <param name="fileFilter">文件过滤, 例如*.xml,这样只压缩.xml文件.</param> /// public bool ZipFileMain(string zippath, string zipfilename, string fileFilter) { try { //string filenames = Directory.GetFiles(args[0]); Crc32 crc = new Crc32(); ZipOutputStream s = new ZipOutputStream(File.Create(zipfilename)); s.SetLevel(6); // 0 – store only to 9 – means best compression DirectoryInfo di = new DirectoryInfo(zippath); FileInfo[] a = di.GetFiles(fileFilter); cutStr = zippath.Trim(); //压缩这个目录下的所有文件 writeStream(ref s, a, crc); //压缩这个目录下子目录及其文件 direct(di, ref s, crc); s.Finish(); s.Close(); } catch { return false; } return true; }