Пример #1
0
    public ReturnValue UnZipFiles(string zipFilePath, string password)
    {
        ReturnValue _result = new ReturnValue();

        #region 检查压缩文件
        if (File.Exists(zipFilePath) == false)
        {
            _result.Success    = false;
            _result.ErrMessage = "没找到文件 " + zipFilePath;

            return(_result);
        }



        #endregion

        #region 解压文件
        //目录结尾
        string targetpath = System.IO.Path.GetDirectoryName(zipFilePath) + "\\" + System.IO.Path.GetFileNameWithoutExtension(zipFilePath);

        if (Directory.Exists(targetpath) == false)
        {
            Directory.CreateDirectory(targetpath);
        }

        List <string> files = ZipCommon.UnZipFiles(zipFilePath, targetpath, password);

        _result.ObjectValue = files;

        #endregion

        return(_result);
    }
Пример #2
0
    public void ExportFileByZip(int apployInfoId)
    {
        YHFramework.DAL.ApployInfoDal        apployInfoDal = new ApployInfoDal();
        YHFramework.SysModel.ApployInfoModel model         = apployInfoDal.GetModel(apployInfoId);
        OutFileFactory FileFactory  = new OutFileFactory();
        IOutFile       outfile      = FileFactory.CreateNewObj(GetOutFileType(apployInfoId));
        FileInfo       fileinfo     = new FileInfo(model.FileName);
        string         fileanme     = fileinfo.Name.Replace(fileinfo.Extension, "");
        string         tempfilename = fileanme + outfile.ExtName;
        string         zipfilename  = fileanme + ".zip";
        string         tempfilepath = System.AppDomain.CurrentDomain.BaseDirectory + "tempfile\\";
        string         zipfilepath  = System.AppDomain.CurrentDomain.BaseDirectory + "down\\";

        if (Directory.Exists(tempfilepath) == false)
        {
            Directory.CreateDirectory(tempfilepath);
        }

        #region 清理文件

        if (File.Exists(tempfilepath + tempfilename))
        {
            File.Delete(tempfilepath + tempfilename);
        }

        if (File.Exists(zipfilepath + zipfilename))
        {
            File.Delete(zipfilepath + zipfilename);
        }

        #endregion

        #region 写入临时文件

        int pagezise  = 20000;
        int pagecount = 0;
        int datacount = 0;


        YHFramework.DAL.CodeDataDal codedatadal = new CodeDataDal();
        string sqlwhere = " and ApployInfoId=" + apployInfoId + " ";
        datacount = codedatadal.GetCount(sqlwhere, "");
        if (datacount % pagezise == 0)
        {
            pagecount = datacount / pagezise;
        }
        else
        {
            pagecount = datacount / pagezise + 1;
        }

        for (int i = 1; i <= pagecount; i++)
        {
            DataTable dt = codedatadal.GetPageList(" a.* ", "", sqlwhere, i, pagezise);
            outfile.OutFilePath = tempfilepath;
            outfile.FileName    = tempfilename;
            outfile.OutFile(dt);
        }


        #endregion

        #region 压缩
        bool result = ZipCommon.ZipFile(tempfilepath + tempfilename, zipfilepath, fileanme, 5, 2048, model.Secret);
        if (result)
        {
            this.txtMsg.Text = "压缩成功";
        }
        else
        {
            this.txtMsg.Text = "压缩失败";
        }
        #endregion

        #region 更新任务

        #endregion
    }