我正在尝试从WebAPI Rest服务中读取并返回文件内容,我正在返回使用..块内的响应。我得到System.ObjectDisposedException。有人可以帮我弄这个吗?无法访问已关闭的文件System.ObjectDisposedException
using (var fileStream = new FileStream(LocalFilePath, FileMode.Open))
{
response.Content = new StreamContent(fileStream);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "MaxRecords.xls" };
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");
return response;
}
不要使用“使用”块吗? – Evk
它工作如果你删除使用块? 'response.Content'引用了一个被放置的实例('fileStream')。 –
@DaveBecker是的,它使用块删除后工作..但我想用块来处理文件流:( –