469,642 Members | 1,217 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

problem with pdfs

My aspx page code reads some custom values from the HTTP headers and then
writes a given pdf to the output stream based upon the header values.
Unforunately, my code causes IE to pop up an Open / Save dialog instead of
invoking the Adobe plugin and displaying the pdf inside of I.E. Here is my
code (file points to a valid pdf and mimetype is set to 'application/pdf')

private void RenderFile(FileInfo file, string mimeType){

this.Context.Response.ContentType = mimeType;

Debug.WriteLine(this.Context.Response.ContentType) ;

this.Context.Response.AddHeader("Content-Length",
file.Length.ToString());

byte[] buffer = new byte[1024];
int bytesRead = -1;

FileStream fs = new FileStream(file.FullName, FileMode.Open,
FileAccess.Read);
Debug.WriteLine(fs.Length);

Stream output = this.Context.Response.OutputStream;

int i = 0;
while ( (bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0 ){

output.Write(buffer, 0, bytesRead);
}

output.Close();
}

Watched the HTTP traffic through a tunnel and noticed that ASP.NET is
tacking on a content-type of utf-8 on the response (even though my code set
it to application/pdf).

HTTP request
GET /webtier/PcFileRetriever.aspx?queryStringParams omitted for brevity
HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
*/*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
1.1.4322)
Host: localhost:81
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=dqnbdy45x0plax344a1drb55

HTTP response
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Wed, 16 Jul 2003 19:41:41 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Cache-Control: private
Content-Type: application/pdf; charset=utf-8
Content-Length: 12850530

Anyone know how to properly stream the pdf file so the IE Adobe browser
plugin displays it instead of prompting the user to save? thanks

scott
Nov 17 '05 #1
0 1397

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mark | last post: by
reply views Thread by billby | last post: by
4 posts views Thread by Ragnar Heil | last post: by
14 posts views Thread by BlueDolphin | last post: by
2 posts views Thread by Pawan | last post: by
3 posts views Thread by Null | last post: by
3 posts views Thread by Mike Kingscott | last post: by
reply views Thread by praveenkhade | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.