我想通过使用.net框架类从我的mvc.net c#应用程序创建zip文件。 请尽快回复我。使用c#生成zip文件代码
2
A
回答
1
使用外部库如this one或this one。 例如与DotNetZip你可以做一个zip文件是这样的:
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
// add the report into a different directory in the archive
zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
zip.AddFile("ReadMe.txt");
zip.Save("MyZipFile.zip");
}
3
你看着SharpZipLib?我用
3
一个第三方库是http://dotnetzip.codeplex.com/
我喜欢它比SharpZipLib多了不少 - SharpZipLib是不是真的很直观地奠定了在所有。
2
随着.NET 4.5你现在可以真正轻松地使用.NET Framework创建zip文件:
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
直接从微软的文档采取上面的代码:http://msdn.microsoft.com/en-us/library/ms404280(v=vs.110).aspx
还有其他的方法生成压缩文件,在上面链接的页面上进一步解释。
相关问题
- 1. 使用System.IO.Packaging生成一个ZIP文件
- 2. 如何使用C#代码生成随机大图像文件?
- 3. C#代码生成
- 4. C++代码生成
- 5. 使用Python进行C++代码生成
- 6. 由PHP文件生成的Zip文件
- 7. 如何使用Gradle生成我的源代码ZIP?
- 8. 使用PDF生成ZIP内
- 9. 使用.net生成代码
- 10. 使用Ant生成代码
- 11. 使用EMF生成代码
- 12. 使用Scala代码生成
- 13. 使用yacc代码生成
- 14. 从C#代码生成汇编代码?
- 15. 从使用Python实现的matlab代码生成C代码Scipy
- 16. 使用ADO.NET生成代码后重组代码DbContext生成器
- 17. 如何使用宁静代码生成器生成代码(.ts)
- 18. 从* .slx生成C++代码
- 19. C代码生成器#
- 20. 如何生成c#代码?
- 21. Qt Designer生成C++代码
- 22. C代码生成模板
- 23. C#代码生成器
- 24. Matlab simulink c代码生成
- 25. CFG生成的C#代码
- 26. C#SQLMetal生成的代码
- 27. 从C#生成XML代码
- 28. antlr3 c#代码生成
- 29. joomla ZipArchive生成无效的zip文件
- 30. 从servlet下载生成的zip文件
我会用下面的答案之一,但如果你在一个他们不喜欢第三方dll的地方工作,我会在今天早些时候链接到我对类似问题的回答:http:/ /stackoverflow.com/questions/3437770/how-to-extract-zip-file-using-dotnet-framework-4-0-without-using-third-party-dlls/3438147#3438147 – 2010-08-09 14:33:52