Exemple #1
0
        /// <summary>
        /// get list of files
        /// </summary>
        /// <param name="path">virtual directory</param>
        /// <returns>list of files</returns>
        public IEnumerable<UplFile> GetFiles(string path)
        {
            path = string.Concat(Root, "/", path);
            path = MapPath(path);
            var list = new List<UplFile>();
            var files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                var finfo = new FileInfo(file);

                var item = new UplFile
                {
                    FileName = finfo.Name,
                    Modified = finfo.LastWriteTime,
                    Extension = finfo.Extension,
                    FileSize = finfo.Length
                };

                list.Add(item);
            }

            return list;
        }
Exemple #2
0
        /// <summary>
        /// get files in path
        /// </summary>
        /// <param name="path">path</param>
        /// <returns>list of files</returns>
        public IEnumerable<UplFile> GetFiles(string path)
        {
            var list = new List<UplFile>();

            path = path.TrimStart('/');

            var request = new ListObjectsRequest
            {
                BucketName = _bucket
            };

            var response = _client.ListObjects(request);

            var objects = from x in response.S3Objects
                          where x.Key.StartsWith(path)
                          select x;

            var things = objects.ToList();

            foreach (var obj in things)
            {
                var pathLength = path.Length;
                var fileName = obj.Key.Substring(pathLength).TrimStart('/');
                if (!FileIsInRoot(fileName)) continue;

                var item = new UplFile
                {
                    FileName = fileName,
                    Modified = Convert.ToDateTime(obj.LastModified),
                    Extension = Path.GetExtension(fileName),
                    FileSize = obj.Size
                };

                list.Add(item);
            }

            return list;
        }