Ejemplo n.º 1
0
        /// <summary>根据FileID获得相关文件流, wang加</summary>
        public async Task <DownloadResult> DownloadAsync(string id)
        {
            var             result  = new DownloadResult();
            DownloadRequest request = new DownloadRequest();
            var             file    = await _fileMan.GetByIdAsync(id);

            if (file == null)
            {
                throw new Exception("指定文件不存在");
            }
            request.FileName   = file.Name;
            request.ContentRef = file.RelativePath;
            return(DownloadAsync(request, file));
        }
Ejemplo n.º 2
0
        DownloadResult DownloadAsync(DownloadRequest request, SysFile file)
        {
            var result = new DownloadResult();

            result.FileName = request.FileName; //wang加
            var relativePath = request.ContentRef.Replace('/', '\\');

            if (result.FileName.IsEmpty())
            {
                result.FileName = Path.GetFileName(relativePath);
            }
            var filePath = this._uploadPath + relativePath;

            if (File.Exists(filePath))
            {
                result.Content = File.OpenRead(filePath);
            }
            else
            {
                throw new Exception("指定文件不存在");
            }
            result.ContentType = file.ContentType;
            return(result);
        }