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

            if (file == null)
            {
                throw new Exception("指定文件不存在");
            }
            return(Download(file));
        }
Exemple #2
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));
        }
Exemple #3
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);
        }
Exemple #4
0
        /// <summary>
        /// 根据指定SysFile文件实体信息下载文件,即使SysFile不在数据库中
        /// </summary>
        /// <param name="file">SysFile文件实体信息</param>
        /// <returns>文件下载结果</returns>
        public DownloadResult Download(SysFile file)
        {
            var result = new DownloadResult();

            result.FileName = file.Name;
            var relativePath = file.RelativePath;

            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);
        }