压缩CSV文件 [英] Zipping CSV File

查看:303
本文介绍了压缩CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在尝试将csv文件压缩到C驱动器.我有一个获取Sales.csv文件的方法,它将csv文件保存到C驱动器,但是当我使用此代码压缩它时,它不起作用.请协助我所缺少的:-(

Hi there,

I''m trying to zip a csv file to the C drive. I have a method that gets the Sales.csv file and it saves the csv file to the C drive but then when I use this code to zip it, it doesn''t work. please assist what am I missing :-(

ProcessStartInfo ps = new ProcessStartInfo();
                    ps.UseShellExecute = true;
                    ps.Arguments = @"C:\Sales" + dr["dbkey"].ToString() + ".csv";
                    
                    ps.FileName = "C:\\Program Files\\WinZip\\WZZIP.EXE";
                    Process p = Process.Start(ps);
                    p.WaitForExit();



问候,
Graduate



Regards,
Graduate

推荐答案

而不是尝试启动一个外部应用程序(该应用程序可能存在也可能不存在,并且是最新的并且可以正常使用),而是使用C#库.您可以在Google的"MSDN"中查找在MSDN上 [
Rather than try to kick off an external application (which may or may not be present, up to date and working ok) use C# libraries instead. Either Google for "Zip file in c#" or look at MSDN here[^]


在除了OriginalGriff的答案外,您还可以尝试
In addition to OriginalGriff''s answer you can also try Sharpziplib[^]


是否可能是您在此处缺少反斜杠:

ps.Arguments = @"C:\ Sales \ " + dr ["dbkey"].ToString()+".csv";

???

尝试调试Arguments值,看看它确实是您要压缩的文件的有效路径

除此之外,这是一个很好的zip库,可以直接从.NET使用:

ZipStorer-用于在Zip中存储文件的纯C#类 [
Could it be that you''re missing a backslash here:

ps.Arguments = @"C:\Sales\" + dr["dbkey"].ToString() + ".csv";

???

Try debugging the Arguments value and see that it is really the valid path to the file you want to zip

Apart from that, this is a good zip library that can be used directly from .NET:

ZipStorer - A Pure C# Class to Store Files in Zip[^]


这篇关于压缩CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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