[ZT]C# 利用WinRAR (加密)压缩及解压缩 相关文件夹及文件

原文摘自 http://www.cnblogs.com/freeliver54/archive/2007/01/17/622992.aspx

本次示例主要实现:
1.压缩文件夹及其下文件
2.压缩文件夹下文件
3.压缩文件夹及其下文件为rar 还是 zip
4.解压缩
5.加密压缩及解加密压缩
-----------
示例代码如下:
protected void Button1_Click(object sender, EventArgs e)
    {
        string strtxtPath = "C:\\freezip\\free.txt";
        string strzipPath = "C:\\freezip\\free.zip";
        System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
        Process1.StartInfo.FileName = "Winrar.exe";
        Process1.StartInfo.CreateNoWindow = true;

        1
        压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
        到c:\freezip\free.rar
        //strzipPath = "C:\\freezip\\free";//默认压缩方式为 .rar
        //Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strtxtPath;

        2
        压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
        到c:\freezip\free.rar
        //strzipPath = "C:\\freezip\\free";//设置压缩方式为 .zip
        //Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strtxtPath;

        3
        压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
        到c:\freezip\free.zip  直接设定为free.zip
        //Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strtxtPath ;

        4
        搬迁压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
        到c:\freezip\free.rar 压缩后 原文件将不存在
        //Process1.StartInfo.Arguments = " m " + strzipPath + " " + strtxtPath;

        5
        压缩c:\freezip\下的free.txt(即文件free.txt)
        到c:\freezip\free.zip  直接设定为free.zip 只有文件 而没有文件夹
        //Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath;

        6
        解压缩c:\freezip\free.rar
        到 c:\freezip\
        //strtxtPath = "c:\\freezip\\";
        //Process1.StartInfo.Arguments = " x " + strzipPath + " " + strtxtPath;

        7
        加密压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
        到c:\freezip\free.zip  密码为123456 注意参数间不要空格
        //Process1.StartInfo.Arguments = " a -p123456 " + strzipPath + " " + strtxtPath;

         8
        解压缩加密的c:\freezip\free.rar
        到 c:\freezip\   密码为123456 注意参数间不要空格
        //strtxtPath = "c:\\freezip\\";
        //Process1.StartInfo.Arguments = " x -p123456 " + strzipPath + " " + strtxtPath;

       9 
       -o+ 覆盖 已经存在的文件
       -o- 不覆盖 已经存在的文件
       //strtxtPath = "c:\\freezip\\";
       //Process1.StartInfo.Arguments = " x -o+ " + strzipPath + " " + strtxtPath;

       10
       只从指定的zip中
       解压出free1.txt
       到指定路径下
       压缩包中的其他文件 不予解压
       //strtxtPath = "c:\\freezip\\";
       //Process1.StartInfo.Arguments = " x " + strzipPath + " " +" free1.txt" + " " + strtxtPath;

       11
       通过 -y 对所有询问回应为"是" 以便 即便发生错误 也不弹出WINRAR的窗口
       -cl 转换文件名为小写字母 
      //strtxtPath = "c:\\freezip\\";
      //Process1.StartInfo.Arguments = " t -y -cl " + strzipPath + " " + " free1.txt";

        Process1.Start();   
        if (Process1.HasExited)
        {
                int iExitCode = Process1.ExitCode;
                if (iExitCode == 0)
                {
                    Response.Write(iExitCode.ToString() + " 正常完成");
                }
                else
                {
                    Response.Write(iExitCode.ToString() + " 有错完成");
                }
        }
    }

转载于:https://www.cnblogs.com/Samples/archive/2010/12/26/1917065.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于使用C#编程语言控制Zebra ZT210打印机,您可以通过以下步骤进行操作: 1. 首先,确保您已经安装了Zebra打印机驱动程序。您可以从Zebra官方网站上下载并安装最新的驱动程序。 2. 在C#项目中,您需要引用Zebra打印机的相关库。您可以从NuGet包管理器中搜索并安装Zebra打印机的软件开发包(SDK)。 3. 在代码中,您需要初始化打印机连接。可以通过以下代码示例来实现: ```csharp using System; using Zebra.Sdk.Comm; using Zebra.Sdk.Printer; public class ZebraPrinterControl { private Connection printerConnection; public void ConnectToPrinter(string printerIp) { printerConnection = new TcpConnection(printerIp, TcpConnection.DEFAULT_ZPL_TCP_PORT); printerConnection.Open(); } public void DisconnectFromPrinter() { printerConnection?.Close(); } public void SendZplCommands(string zplCommands) { ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); printerConnection.Write(Encoding.UTF8.GetBytes(zplCommands)); } } ``` 4. 您可以使用上述代码中的`ConnectToPrinter`方法来连接到打印机。请确保将打印机的IP地址传递给此方法。 5. 使用`SendZplCommands`方法发送ZPL命令到打印机。例如,要打印一段文本,您可以使用以下代码示例: ```csharp ZebraPrinterControl printerControl = new ZebraPrinterControl(); printerControl.ConnectToPrinter("打印机的IP地址"); printerControl.SendZplCommands("^XA^FO50,50^ADN,36,20^FDHello World^FS^XZ"); printerControl.DisconnectFromPrinter(); ``` 上述代码中的ZPL命令`^XA^FO50,50^ADN,36,20^FDHello World^FS^XZ`在打印纸上绘制了一个文本字符串"Hello World"。 请注意,以上代码仅为示例,您可能需要根据自己的需求进行适当的修改和调整。此外,在使用打印机之前,请确保您已经充分了并熟悉了ZPL语言以及Zebra打印机的功能和配置。 希望对您有帮助!如果您还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值