Exemplo n.º 1
0
 public void CollectFiles(DirectoryInfo directory, FilePackage package)
 {
     directory.GetDirectories().Each(dir => CollectFiles(dir, package));
     directory.GetFiles().Each(file =>
     {
         package.Files.Add(new FileInfo {
             FileName = file.Name, FilePath = file.FullName.Replace(MapPath("~/"), "~/"), Content = File.ReadAllBytes(file.FullName)
         });
     });
 }
Exemplo n.º 2
0
        public virtual Package Pack(object obj)
        {
            FilePackage package   = CreatePackage();
            var         directory = obj as DirectoryInfo;

            if (directory != null)
            {
                CollectFiles(directory, package);
            }
            else
            {
                var files = obj as IEnumerable <System.IO.FileInfo>;
                if (files != null)
                {
                    files.Each(file =>
                    {
                        package.Files.Add(new FileInfo {
                            FileName = file.Name, FilePath = file.FullName.Replace(MapPath("~/"), "~/"), Content = File.ReadAllBytes(file.FullName)
                        });
                    });
                }
            }
            return(package);
        }