示例#1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="buffer">文件内容的字节数组</param>
        public BinaryResult(byte[] buffer)
        {
            if (buffer == null || buffer.Length == 0)
            {
                throw new ArgumentNullException("buffer");
            }

            _streamResult = new StreamResult(buffer);
        }
        /// <summary>
        /// 实现IActionResult接口,执行输出
        /// </summary>
        /// <param name="context"></param>
        public void Ouput(HttpContext context)
        {
            // 设置当前响应的文档类型
            context.Response.ContentType = StreamResult.DefaultContentType;

            // 设置浏览器下载对话框中的保存文件名称
            StreamResult.SetDownloadFileName(context, _downLoadFileName);

            // 下载文件
            context.Response.TransmitFile(_filePath);
        }