Ejemplo n.º 1
0
        public static bool ZipFile(string path)
        {
            try
            {
                //ten file zip
                string strZipFilename = "";
                //password
                string strPass = "";
                //duong dan file xml can zip
                string[]        filenames = System.IO.Directory.GetFiles(path, "*.xml");
                clsCryptography genPass   = new clsCryptography();

                foreach (string file in filenames)
                {
                    //lay file nam xml , thay extension thang .zip
                    strZipFilename = file.Substring(0, file.Length - 4) + ".zip";
                    //generate password
                    strPass = genPass.GenPWDByFilename(strZipFilename);
                    //zip file
                    clsZip.ZipFiles(file, strZipFilename, strPass);
                    //xoa file xml sau khi da zip xong
                    System.IO.File.Delete(file);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static void SaveZipFile2(DataSet ds, String filename)
        {
            ds.WriteXml(filename, XmlWriteMode.WriteSchema);
            FileInfo        file           = new FileInfo(filename);
            String          nameWithoutExt = GetNameWithoutExt(file.Name);
            String          newName        = file.DirectoryName + "/" + nameWithoutExt + ".zip";
            clsCryptography crypto         = new clsCryptography();
            String          pwd            = crypto.GenPWDByFilename(newName);

            clsZip.ZipFiles(filename, newName, pwd);
            file.Delete();
        }
Ejemplo n.º 3
0
 public static DataSet ReadZipFile(String filename)
 {
     FileInfo file = new FileInfo(filename);
     String tmpFolder = GenerateTempFolderName(file.FullName);
     Directory.CreateDirectory(tmpFolder);
     clsCryptography crypto = new clsCryptography();
     String pwd = crypto.GenPWDByFilename(file.Name);
     clsZip.UnzipFile(file.FullName, tmpFolder, pwd);
     String filename2 = GetFirstFile(tmpFolder);
     DataSet ds = new DataSet();
     ds.ReadXml(filename2);
     DeleteFolder(tmpFolder);
     return ds;
 }
Ejemplo n.º 4
0
        public static DataSet ReadZipFile(String filename)
        {
            FileInfo file      = new FileInfo(filename);
            String   tmpFolder = GenerateTempFolderName(file.FullName);

            Directory.CreateDirectory(tmpFolder);
            clsCryptography crypto = new clsCryptography();
            String          pwd    = crypto.GenPWDByFilename(file.Name);

            clsZip.UnzipFile(file.FullName, tmpFolder, pwd);
            String  filename2 = GetFirstFile(tmpFolder);
            DataSet ds        = new DataSet();

            ds.ReadXml(filename2);
            DeleteFolder(tmpFolder);
            return(ds);
        }
Ejemplo n.º 5
0
        public static bool ZipFile(string path)
        {
            try
            {
                //ten file zip
                string strZipFilename = "";
                //password
                string strPass = "";
                //duong dan file xml can zip
                string[] filenames = System.IO.Directory.GetFiles(path, "*.xml");
                clsCryptography genPass = new clsCryptography();

                foreach (string file in filenames)
                {
                    //lay file nam xml , thay extension thang .zip
                    strZipFilename = file.Substring(0, file.Length -4) + ".zip";
                    //generate password
                    strPass = genPass.GenPWDByFilename(strZipFilename);
                    //zip file
                    clsZip.ZipFiles(file, strZipFilename, strPass);
                    //xoa file xml sau khi da zip xong
                    System.IO.File.Delete(file);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Zip file
        /// </summary>
        /// <remarks>
        /// Author			:	Nguyen Bao Nguyen G3
        /// Created day		:	24-Apr-2011
        /// </remarks>
        public void ZipFileParam(string strParamPath)
        {
            try
            {
                //string strFileNameToEncode = "";
                string strZipFilename = "";
                string strPass = "";

                string strPath = strParamPath;
                string[] filenames = Directory.GetFiles(strPath, "*.xml");
                clsCryptography genPass = new clsCryptography();

                foreach (string file in filenames)
                {
                    strZipFilename = file.Substring(0, file.Length -4)+".zip";
                    //strFileNameToEncode = file.Substring(0, file.Length -4);
                    strPass = genPass.GenPWDByFilename(strZipFilename);
                    clsZip.ZipFiles(file, strZipFilename, strPass);
                    File.Delete(file);
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
 public static void SaveZipFile(DataSet ds, String filename)
 {
     FileInfo file = new FileInfo(filename);
     String nameWithoutExt = GetNameWithoutExt(file.Name);
     String newName = file.DirectoryName + "/" + nameWithoutExt + ".xml";
     ds.WriteXml(newName, XmlWriteMode.WriteSchema);
     clsCryptography crypto = new clsCryptography();
     String pwd = crypto.GenPWDByFilename(filename);
     clsZip.ZipFiles(newName, filename, pwd);
     File.Delete(newName);
 }