I have a page that I use to pull a file from the database and either prompt for download or stream to the browser depending on how the URL is formatted. This is working fine, however nothing I do will work when trying to set the page title and it defaults to the domain name in the URL.
I realize this is most likely happening because I am sending a binary file to the browser using Response.OutputStream.Write(buffer, 0, bytesRead) and so according to something else I found online “I am filling up the buffer with the binary file so I have no control over the title”
You are filling up the buffer with a binary file, with no HTML and hence no Title Tag. I am not sure you have any control over the Title tag in the browser at this point. Let me check on a page I have up right now with a PDF. It does not look like this can be done, at least in the example I am looking at. I had another PDF opened, but it was to a local file directly and it had the Title tag set in the browser. I am not sure if this was embedded in the PDF or not.
Found here: http://forums.asp.net/t/1088814.aspx/1
I have tried all the normal places to set the page title:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FileServer.aspx.vb" Inherits="FileServer" Title="Title goes here" %>
or
<head runat="server">
<title>Title goes here</title>
</head>
or
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim FileNumber As String = RouteData.Values("FileNumber")
Dim Disposition As String = RouteData.Values("Disposition")
If FileNumber IsNot Nothing Then
Title = "Title goes here"
ServeFile(FileNumber, Disposition)
End If
End Sub
Is there any way for me to set this title or am I out of luck?
You cannot set the title while at the same time sending a file down to the browser. For the browser to change the “page” title, it needs to actually render an HTML document (ie. it needs to render a page).
In this situation you’re not sending any valid HTML content, hence the fact that the contents you are sending are downloaded.
If you want to do this, what you will need to do is do a sort of “bounce”. Redirect to a page that renders out the title, and any other content that you want (ie. an aspx page). And from that page “bounce” the browser over to the download.