求解!!!比如传一张图片  1.jpg   然后自动打包成 1.rar 这个如何搞??

解决方案 »

  1.   

    服务器上装WINRAR,用WINRAR的接口。。
      

  2.   

    http://blog.csdn.net/ZZJ_4Ever/article/details/4038595
      

  3.   

    http://blog.csdn.net/yuanmanguo/article/details/4195536  C#调用RAR压缩与解压 
      

  4.   

    //下载ICSharpCode.SharpZipLib.dll,并引用之
    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.IO;
    using ICSharpCode.SharpZipLib.Checksums;
    using ICSharpCode.SharpZipLib.Zip;
    using System.Collections.Generic;    private bool Zip(string strZipPath, string strZipTopDirectoryPath, int intZipLevel, string strPassword, string[] filesOrDirectoriesPaths)
        {
            try
            {
                List<string> AllFilesPath = new List<string>();
                if (filesOrDirectoriesPaths.Length > 0) // get all files path
                {
                    for (int i = 0; i < filesOrDirectoriesPaths.Length; i++)
                    {
                        if (File.Exists(filesOrDirectoriesPaths[i]))
                        {
                            AllFilesPath.Add(filesOrDirectoriesPaths[i]);
                        }
                        else if (Directory.Exists(filesOrDirectoriesPaths[i]))
                        {
                            GetDirectoryFiles(filesOrDirectoriesPaths[i], AllFilesPath);
                        }
                    }
                }            if (AllFilesPath.Count > 0)
                {                ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create(strZipPath));
                    zipOutputStream.SetLevel(intZipLevel);
                    zipOutputStream.Password = strPassword;                for (int i = 0; i < AllFilesPath.Count; i++)
                    {
                        string strFile = AllFilesPath[i].ToString();
                        try
                        {
                            if (strFile.Substring(strFile.Length - 1) == "") //folder
                            {
                                string strFileName = strFile.Replace(strZipTopDirectoryPath, "");
                                if (strFileName.StartsWith(""))
                                {
                                    strFileName = strFileName.Substring(1);
                                }
                                ZipEntry entry = new ZipEntry(strFileName);
                                entry.DateTime = DateTime.Now;
                                zipOutputStream.PutNextEntry(entry);
                            }
                            else //file
                            {
                                FileStream fs = File.OpenRead(strFile);                            byte[] buffer = new byte[fs.Length];
                                fs.Read(buffer, 0, buffer.Length);                            string strFileName = strFile.Replace(strZipTopDirectoryPath, "");
                                if (strFileName.StartsWith(""))
                                {
                                    strFileName = strFileName.Substring(0);
                                }
                                ZipEntry entry = new ZipEntry(strFileName);
                                entry.DateTime = DateTime.Now;
                                zipOutputStream.PutNextEntry(entry);
                                zipOutputStream.Write(buffer, 0, buffer.Length);                            fs.Close();
                                fs.Dispose();
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }                zipOutputStream.Finish();
                    zipOutputStream.Close();                return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }
    //调用:
        protected void Button1_Click(object sender, EventArgs e)
        {
            //string ph=Server.MapPath("~/zip");
            //dlZipDir(ph, "1");
            //Label1.Text = ph;        string strZipPath = Server.MapPath("~/zip/1.zip");//生成压缩文件路径和文件名
            string strZipTopDirectoryPath = Server.MapPath("~/zip");//源文件的上级目录
            int intZipLevel = 6;//压缩等级
            string strPassword = "";//压缩包解压密码
            string[] filesOrDirectoriesPaths = new string[] { Server.MapPath("~/zip/1.jpg") };//源文件路径
            Zip(strZipPath, strZipTopDirectoryPath, intZipLevel, strPassword, filesOrDirectoriesPaths);
        }
      

  5.   

    1、图片用rar是无法压缩的。
    2、如果多个图片打包用8楼的方法