76 字
1 分钟
.NET WebApi下载文件
来自于一个从服务端下载文件的需求。偶尔会出现中文乱码,待探究。
public IActionResult Get() { const string str = @"D:\YaKun\Downloads\测试文件.txt"; return new FileStreamResult(new FileStream(str, FileMode.Open), new MediaTypeHeaderValue("application/octet-stream")) { FileDownloadName = "测试文件.txt", //下载的文件名 EnableRangeProcessing = true //文件流范围支持 }; }