ASP.NET Filestream如何读取pdf文件,应该如何做?
& lt% @ Page Language = " c# " & gt;
& lt% @ Import Namespace = " System " % & gt;
& lt%@ Import Namespace="System。IO " % & gt
& lt%
回应。clear();
string path = @ " f:\ TD download \ book \ c #游戏编程入门。pdf ";
回应。content type = " application/pdf ";
response . add header(" content-disposition "," filename =游戏编程入门。pdf”);
byte[] buffer =新字节[256];
FileStream fs = File。打开(路径,文件模式。打开);
回应。AddHeader("content-length ",fs。length . ToString());
int长度= (int)fs。长度;
如果(回应。IsClientConnected)
{
while(长度& gt-1)
{
长度=长度-缓冲区。长度;
fs。读取(buffer,0,buffer。长度);
回应。OutputStream.Write(缓冲区,0,缓冲区。长度);
}
}
fs。close();
回应。end();
% & gt
是的,这就是网页上显示的内容。