LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

[点晴永久免费OA]C#程序B/S打包下载

admin
2020年3月3日 1:38 本文热度 2533

      protected void btnAdd_Click(object sender, EventArgs e)
        {
            // 创建临时文件夹
            string Folder = DateTime.Now.ToString("yyyymmddHHMMss");
            string tempFolder = Path.Combine(Server.MapPath("/file"), Folder);
            Directory.CreateDirectory(tempFolder);
            string[] fs = Directory.GetFiles(Server.MapPath("/files"));
            for (int i = 0; i < fs.Length; i++)
            {
                File.Copy(fs[i], tempFolder + fs[i].Substring(fs[i].LastIndexOf(''\\''), fs[i].Length - fs[i].LastIndexOf(''\\'')));
            }

            //产生RAR文件,及文件输出
            RARsave(tempFolder, tempFolder, Folder);
            ResponseFile(tempFolder + @"\" + Folder + ".rar");
        }
        public void RARsave(string patch, string rarPatch, string rarName)
        {
            String the_rar;
            RegistryKey the_Reg;
            Object the_Obj;
            String the_Info;
            ProcessStartInfo the_StartInfo;
            Process the_Process;
            try
            {
                the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR");
                the_Obj = the_Reg.GetValue("");
                the_rar = the_Obj.ToString();
                the_Reg.Close();
                the_rar = the_rar.Substring(1, the_rar.Length - 7);
                Directory.CreateDirectory(patch);

                //命令参数
                //the_Info = " a    " + rarName + "  " + @"C:Test?70821.txt"; //文件压缩
                the_Info = " a " + rarName + "  " + patch + "  -r";
                the_StartInfo = new ProcessStartInfo();
                the_StartInfo.FileName = "WinRar";//the_rar;
                the_StartInfo.Arguments = the_Info;
                the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                //打包文件存放目录
                the_StartInfo.WorkingDirectory = rarPatch;
                the_Process = new Process();
                the_Process.StartInfo = the_StartInfo;
                the_Process.Start();
                the_Process.WaitForExit();
                the_Process.Close();

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void ResponseFile(string fileName)
        {

            FileInfo fileInfo = new FileInfo(fileName);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "binary");
            Response.ContentType = "application/octet-stream";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.WriteFile(fileInfo.FullName);
            Response.Flush();
            string tempPath = fileName.Substring(0, fileName.LastIndexOf("\\"));
            DelDir(tempPath);
            Directory.Delete(tempPath);
            Response.End();
         
          
        }
        private void DelDir(string path)
        {
            string[] fs = Directory.GetFiles(path);
            for (int i = 0; i < fs.Length; i++)
            {
                File.Delete(fs[i]);
            }
              
        }


该文章在 2020/3/3 1:38:32 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved