Asp.net 从网页上的二进制数组下载文件

Asp.net 从网页上的二进制数组下载文件,asp.net,Asp.net,我有二进制数组形式的文件,我需要浏览器打开下载对话框并保存文件 我试过了 Response.BinaryWrite(fileData); 但它只是在页面中添加了二进制字符,没有打开下载对话框 您还需要设置内容类型: Response.ContentType = "application/octet-stream"; 您还需要设置内容类型: Response.ContentType = "application/octet-stream"; 试试这个: Response.Clear(); R

我有二进制数组形式的文件,我需要浏览器打开下载对话框并保存文件

我试过了

Response.BinaryWrite(fileData);

但它只是在页面中添加了二进制字符,没有打开下载对话框

您还需要设置内容类型:

Response.ContentType = "application/octet-stream";

您还需要设置内容类型:

Response.ContentType = "application/octet-stream";
试试这个:

Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=fileToDownload");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(fileData);
Response.Flush();
Response.End();
试试这个:

Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=fileToDownload");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(fileData);
Response.Flush();
Response.End();