如何在表单加载中下载asp.net中的多个文件? [英] How to download multi files in asp.net in form load?

查看:75
本文介绍了如何在表单加载中下载asp.net中的多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

告诉我使用asp.net c#下载多个文件的步骤。我将文件名存储在字符串数组中并放入for循环,但for循环只进行一次。我附上了代码供您参考。请给我解决这个问题的方法。





[注意:由于Response.End(),它不会转到下一个值for循环增量]





 受保护  void  Page_Load( object  sender,EventArgs e)
{
string [] values = { setup1.apk setup1.apk};

for int i = 0 ; i < values.Length; i ++)
{
downloadfiles(values [i]);
}

}

private void downloadfiles( string filename)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ClearContent();
Response.Clear();
Response.ContentType = application / msi;
Response.AppendHeader( Content-Disposition attachment; filename = + filename);
Response.TransmitFile(Server.MapPath( 〜/ jad /)+ filename) ;

Response.End();

}

解决方案

将它们作为文件存档压缩是一个可能的好选择。参见这些文章..

http://www.aspsnippets.com/Articles/Download-multiple-files-as-Zip-Archive-File-in-ASPNet-using-C-and-VBNet.aspx [ ^ ]

http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=333&title=Code-to-Zip-and-Download-File- in-Asp.net-Using-C [ ^ ]

http://csharpdotnetfreak.blogspot.com/2012/07/download-multiple-files-as-zip-aspnet.html [ ^ ]

http://forums.asp.net/p/1343124/2724341.aspx [ ^ ]

http://stackoverflow.com/questions/14224784/how-to-download-multiple-files-using-asp -and-c-sharp [ ^ ]

http://www.aspdotnet-suresh.com/2013/04/aspnet-download-multiple-files-as-zip.html [< a href =http://www.aspdotnet-suresh.com/2013/04/aspnet-download-multiple-files-as-zip.html\"target =_ blanktitle =New Window> ^ ]


http://www.dotnetfunda.com/forums/thread15854-how-to-download-multi-files-in-aspnet-in-form-load.aspx [ ^ ]

http://forums.asp.net/t/1927237.aspx/1?How+to+download+multi+files+in+asp+net+in+form+load+ [ ^ ]

http://www.c-sharpcorner.com/forums/thread/223443/how-to-download-multi-files-in-Asp-Net- in-form-load.aspx [ ^ ]

http://www.dotnetspider.com/forum/328531-How-download-multi-files-asp.net-form -load.aspx [ ^ ]


试试这个...... :)



http://www.aspdotnet-suresh.com/2013/04/ aspnet-download-multiple-files-as-zip.ht ml [ ^ ]

Hi sir,
Tell me the steps to download multi files using asp.net c#. I stored the filenames in string array and put in for loop, but for loop is going one time only. i attached the code for your reference. Kindly give me the solution for this problem.


[Note: Because of Response.End() it will not go to next value increment in for loop]


protected void Page_Load(object sender, EventArgs e)
   {
       string[] values = { "setup1.apk", "setup1.apk" };

       for (int i = 0; i < values.Length; i++)
       {
           downloadfiles(values[i]);
       }

   }

   private void downloadfiles(string filename)
   {
       Response.Cache.SetCacheability(HttpCacheability.NoCache);
       Response.ClearContent();
       Response.Clear();
       Response.ContentType = "application/msi";
       Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
       Response.TransmitFile(Server.MapPath("~/jad/") + filename);
     
       Response.End();

   }

解决方案

Zipping them as file archive is a probable good option.See these articles..
http://www.aspsnippets.com/Articles/Download-multiple-files-as-Zip-Archive-File-in-ASPNet-using-C-and-VBNet.aspx[^]
http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=333&title=Code-to-Zip-and-Download-File-in-Asp.net-Using-C[^]
http://csharpdotnetfreak.blogspot.com/2012/07/download-multiple-files-as-zip-aspnet.html[^]
http://forums.asp.net/p/1343124/2724341.aspx[^]
http://stackoverflow.com/questions/14224784/how-to-download-multiple-files-using-asp-and-c-sharp[^]
http://www.aspdotnet-suresh.com/2013/04/aspnet-download-multiple-files-as-zip.html[^]


http://www.dotnetfunda.com/forums/thread15854-how-to-download-multi-files-in-aspnet-in-form-load.aspx[^]
http://forums.asp.net/t/1927237.aspx/1?How+to+download+multi+files+in+asp+net+in+form+load+[^]
http://www.c-sharpcorner.com/forums/thread/223443/how-to-download-multi-files-in-Asp-Net-in-form-load.aspx[^]
http://www.dotnetspider.com/forum/328531-How-download-multi-files-asp.net-form-load.aspx[^]


Try this...:)

http://www.aspdotnet-suresh.com/2013/04/aspnet-download-multiple-files-as-zip.html[^]


这篇关于如何在表单加载中下载asp.net中的多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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