Пример #1
0
        private void DownloadImages(List <string> fileNames, string FileName)
        {
            string path = PathManager.GetRawPath();

            if (String.IsNullOrEmpty(path))
            {
                throw new Exception("The raw photo path is null or empty");
            }

            string save_path = PathManager.GetDownloadPath();

            if (!Directory.Exists(save_path))
            {
                Directory.CreateDirectory(save_path);
            }

            //closer for save process
            var closer = new Ionic.Zip.CloseDelegate((name, stream) =>
            {
                stream.Dispose();
            });

            using (ZipFile zf = new ZipFile())
            {
                foreach (var file in fileNames)
                {
                    string fullName = file;
                    /* for some reason path combine does not work on the server this needs to be further investigated */
                    if (!fullName.StartsWith(@"\"))
                    {
                        fullName = string.Format(@"{0}\{1}", path, file);
                    }
                    else
                    {
                        fullName = string.Format(@"{0}{1}", path, file);
                    }

                    if (!File.Exists(fullName))
                    {
                        throw new Exception(string.Format(@"The file {0} does not exist", fullName));
                    }

                    var getOpener = new Ionic.Zip.OpenDelegate(name =>
                    {
                        WebClient c = new WebClient();
                        return(c.OpenRead(fullName));
                    });

                    zf.AddEntry(Path.GetFileName(file), getOpener, closer);
                }

                zf.Save(Path.Combine(save_path, FileName));
            }
        }
        private void DownloadImages(List<string> fileNames, string FileName)
        {
            string path = PathManager.GetRawPath();

            if (String.IsNullOrEmpty(path))
            {
                throw new Exception("The raw photo path is null or empty");
            }

            string save_path = PathManager.GetDownloadPath();
            if (!Directory.Exists(save_path))
            {
                Directory.CreateDirectory(save_path);
            }

            //closer for save process
            var closer = new Ionic.Zip.CloseDelegate((name, stream) =>
            {
                stream.Dispose();
            });

            using (ZipFile zf = new ZipFile())
            {
                foreach (var file in fileNames)
                {
                    string fullName = file;
                    /* for some reason path combine does not work on the server this needs to be further investigated */
                    if (!fullName.StartsWith(@"\"))
                    {
                       fullName = string.Format(@"{0}\{1}", path, file);
                    }
                    else
                    {
                        fullName = string.Format(@"{0}{1}", path, file);
                    }

                    if (!File.Exists(fullName))
                    {
                        throw new Exception(string.Format(@"The file {0} does not exist", fullName));
                    }

                    var getOpener = new Ionic.Zip.OpenDelegate(name =>
                    {
                        WebClient c = new WebClient();
                        return c.OpenRead(fullName);
                    });

                    zf.AddEntry(Path.GetFileName(file), getOpener, closer);
                }

                zf.Save(Path.Combine(save_path, FileName));
            }
        }