예제 #1
0
        public void DeleteFile(Guid idFile)
        {
            FileItemInfo file = GetFileInfo(idFile);

            if (file == null)
            {
                return;
            }

            _info.Files.Remove(file);

            File.Delete(Path.Combine(_path, file.FileName));

            _info.Save();
        }
예제 #2
0
        public void AddFile(FileItem file)
        {
            FileItemInfo info = new FileItemInfo
            {
                Id       = file.Id,
                FileName = file.FileName,
                MimeType = file.MimeType
            };

            _info.Files.Add(info);

            using (FileStream fileStream = new FileStream(Path.Combine(_path, file.FileName), FileMode.Create, FileAccess.Write))
            {
                file.Stream.WriteTo(fileStream);
            }

            _info.Save();
        }
예제 #3
0
        public FileItem GetFile(Guid fileId)
        {
            FileItemInfo info = GetFileInfo(fileId);

            if (info == null)
            {
                return(null);
            }

            FileItem item = new FileItem(info.Id)
            {
                FileName = info.FileName,
                MimeType = info.MimeType
            };

            using (FileStream fileStream = new FileStream(Path.Combine(_path, info.FileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                fileStream.CopyTo(item.Stream);
            }

            item.Stream.Position = 0;

            return(item);
        }