On click, generating a file and presenting a Save As dialog box: How to control the default file name
<p>I would like to generate a pdf file when the user clicks on it, an not before. Then after the doc is generated, ideally, I would like to give the user the option to either view the document or download it. If they choose to download, I'd like to display the Save As file dialog box with an appropriate default file name. If they choose to view, I'd like to view the document in a new window regardless of the users local settings for a PDF extension (I'm not sure if a user can control whether a pdf is opened in a new window or now like they can for MS Office file extensions.)</p>

<p>The following code generates the doc and presents the user with a dialog box to save, but the default dialog is the name of the web page(e.g. WebPageName.pdf)  rather  than a default file name that I would prefer.</p>

<p>Is there a way to control what the default file name that is used to prefilled the Save As Dialog box?</p>

<p>I'm not sure how to get all this functionality in one link.</p>

<pre><code>Protected Sub imgPdf_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

    SessionVariables.ChinaVisaId = New SqlInt32(CType(CType(sender, ImageButton).CommandArgument, Integer))
    Dim TargetChinaVisa As ChinaVisa = _Order.ChinaVisas.ItemById(SessionVariables.ChinaVisaId)


    Dim DocName As String = TargetChinaVisa.ReferenceNumber &amp; ".pdf"
    Dim PdfPath As String = Server.MapPath("~/Files/") &amp; DocName
    Dim RelativePath As String = "~/Files/" &amp; DocName
    Dim AbsolutePath As String = "http://" &amp; _SiteName &amp; "/Files/" &amp; DocName

    Dim MyPDF As New ChinaVisaPdf(TargetChinaVisa)

    MyPDF.SaveAsPdf(PdfPath)

    Server.Transfer(RelativePath)

End Subs
</code></pre>

<p>Side question: When opening a doc in a new window, I assume that that has to be done with client side code and an absolute path?</p>
