Beispiel #1
0
        ActionResult IDriver.File(string target, bool download)
        {
            target = this.GetCorectTarget(target);
            target = this.DecodeTarget(target);
            DirInfo dirInfo = client.GetInfo(target);

            if (dirInfo == null)
            {
                throw new ElFinderFileNotExists();
            }
            Stream stream = client.DownloadStream(target);

            return(new WebDavDownloadFileResult(dirInfo, stream, download));
        }
Beispiel #2
0
        public static byte[] GetZip(IList <DirInfo> decTargets, WebDavClient client)
        {
            byte[] data;
            using (var ms = new MemoryStream())
            {
                using (var zip = new ZipFile(Encoding.UTF8))
                {
                    zip.AlternateEncoding      = Encoding.GetEncoding("cp866");
                    zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                    foreach (var dirInfo in decTargets)
                    {
                        var stream = client.DownloadStream(dirInfo.RelPath);
                        if (stream == null)
                        {
                            continue;
                        }
                        var content = Helper.ReadToEnd(stream);
                        if (content != null)
                        {
                            var name = dirInfo.DisplayName;
                            int j    = 1;
                            while (zip.ContainsEntry(name))
                            {
                                name = Path.GetFileNameWithoutExtension(name) +
                                       "(" + j + ")" + Path.GetExtension(name);
                                j++;
                            }
                            zip.AddEntry(name, content);
                        }
                    }

                    zip.Save(ms);
                    data = ms.ToArray();
                }
            }
            return(data);
        }