如何生成和C#ASP.NET发送一个.zip文件到用户? [英] How do I generate and send a .zip file to a user in C# ASP.NET?

查看:209
本文介绍了如何生成和C#ASP.NET发送一个.zip文件到用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构造并发送一个zip给用户。

I need to construct and send a zip to a user.

我见过的例子做一个或另一个,但不能两者,很好奇,如果有任何最佳做法或任何东西。

I've seen examples doing one or the other, but not both, and am curious if there are any 'best practices' or anything.

很抱歉的混乱。我要去产生上飞的网络用户的拉链,并在HTTP响应发送到它们。不是在一封电子邮件。

Sorry for the confusion. I'm going to generating the zip on the fly for the web user, and sending it to them in the HTTP response. Not in an email.

标记

推荐答案

我想第二个投票 SharpZipLib 创建Zip文件。然后,你要一个响应头追加到输出强制下载对话框。

I would second the vote for SharpZipLib to create the Zip file. Then you'll want to append a response header to the output to force the download dialog.

http://aspalliance.com/259

应该给你一个很好的起点,以实现这一目标。基本上,您需要添加一个响应头,设置内容类型和文件写入到输出流:

should give you a good starting point to achieve that. You basically need to add a response header, set the content type and write the file to the output stream:

Response.AppendHeader( "content-disposition", "attachment; filename=" + name );
Response.ContentType = "application/zip";
Response.WriteFile(pathToFile);

这最后一行可以改变到的Response.Write(filecontents),如果你不希望保存到临时文件。

That last line could be changed to a Response.Write(filecontents) if you don't want to save to a temp file.

这篇关于如何生成和C#ASP.NET发送一个.zip文件到用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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