public FileResult GetAuditPrintPdf(string bh,string url)
{
try
{
var client = new WebClient();
string tempFile = Path.GetTempFileName();
client.DownloadFile(url, tempFile);//下载临时文件
var stream = FileToStream(tempFile, true);
return new FileStreamResult(stream, "application/pdf");
}
catch (Exception ex)
{
throw new Exception("文件不存在");
}
}
public static Stream FileToStream(string fileName, bool isDelete = false)
{
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
Stream stream = new MemoryStream(bytes);
if (isDelete)
{
System.IO.File.Delete(fileName);
}
return stream;
}