I would like to change the "page title" for the openned window when a user views an ashx file in the browser. Users click on a document which will open in a new tab in the browser, and the document is shown (i.e. Word, Excel, PDF, etc.). What happens now, is that the page title shows something like "file.ashx?id=5" when I would rather the title show something like "New Document.pdf" or just "New Document" instead of showing the url of the ashx file.
I have looked into setting the filename through a header, that does work, but the file is downloaded instead of simply openning in the broser window. That is not the desired behavior I was going for.
I understand that this may not be possible, but thought I'd check anyway.
Thanks for the help.
For the title of the page: I can only speak to Internet Explorer, but when you show a new window, Internet Explorer requires that the title bar always be displayed (see the MSDN Article About Window Restrictions for more details). The problem when viewing files inline is that you do not send any HTML back to the page so there is no way through this method to have the title change.
I know that we did experiment with several different approaches, but decided that for our user base, it was ok to not have a user-readable value in the title bar. If this is important to you, then I think your only real option would be a frame-based solution where your ashx page is embedded in a frame (or iframe) and the title page is controlled by content in a different frame (or portion of the page in the event you use an iframe).
To view the file in the browser instead of having it downloaded: you need to set the Response ContentType to the appropriate MimeType for the file (i.e. "application/pdf" for PDF files) and add a Content-Disposition header that specifies the file is to be opened inline and the file name for the user. You should also ensure that other content and headers are cleared from the response.
this.Context.Response.ClearContent();
this.Context.Response.ClearHeaders();
this.Context.Response.ContentType = "application/pdf";
this.Context.Response.AddHeader("Content-Disposition", "inline; filename=mytest.pdf");
this.Context.Response.TransmitFile(sLocalFileName);
this.Context.Response.Flush();