Link to home
Start Free TrialLog in
Avatar of JS List
JS ListFlag for United States of America

asked on

Asp.net Change File Name at Runtime?

Hello,

I have a page a that you select a company on -> click Submit -> this takes you to the report.aspx page.  
The report.aspx page has over 300 lines of data in a table.  The table is highly stylized.

What I need to do is either make a PDF with the company name as the filename OR
Produce an .aspx page with the company name as the filename and the user can print it to PDF.  

To create a pdf I've tried using
<%Response.AddHeader("content-disposition", "Attachment;Filename=" & thisCompanyName & ".pdf")
    Response.ContentType = "application/pdf"%>
The file doesn't generate

I've looked at iTextSharp and it looks like it will take a bunch of coding to create the table with all the stylings in it.

To produce a new file
I took the report.aspx and change the page title to the company name then print it physically to pdf - the file comes out with Report.aspx file name.  Tab at the top of the browser displays the correct company name.  (Thought I used this before) No good.

Any ideas?

JS
Avatar of Ark
Ark
Flag of Russian Federation image

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim url = "http://www.htm2pdf.co.uk/convert_url.php"
        Using client = New Net.WebClient
            Dim data As New Specialized.NameValueCollection
            Dim targetUrl = ""http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_28669582.html"
            data.Add("url", targetUrl)
            client.Proxy = Nothing
            Dim bytes = client.UploadValues(url, data)
            Dim response = ""
            Using stm As New IO.MemoryStream(bytes)
                Using reader As New IO.StreamReader(stm)
                    response = reader.ReadToEnd
                End Using
            End Using
            Dim regex = New System.Text.RegularExpressions.Regex("(file=[^>]*)>")
            Dim fileUrl = "http://www.htm2pdf.co.uk/download.php?" & regex.Match(response).Groups(1).Value
            client.DownloadFile(fileUrl, "c:\temp.pdf")
        End Using
    End Sub

Open in new window

here is a windowsapp sample which use html2pdf service. fileUrl is an address to download pdf file. In your web app you can simply add a link with this url. You can do this either from server side using WebClient/WebHTTPRequest or from client side via xmlhttprequest or ajax.
Avatar of JS List

ASKER

The data can't be uploaded anywhere.
Avatar of JS List

ASKER

Is there anyway you can use add header and change the filename when the page is created?  
If the page is called report.aspx -> can I change it to AcmeCo.aspx in the coding?
Avatar of JS List

ASKER

Is it possible for this to happen?
Start out on SelectCompany.aspx    select the company from a drop down
This sends you to report.aspx - Report.aspx is loaded with the data
Can I Copy and rename the report.aspx to newCompanyName.aspx   and transfer to it?
ASKER CERTIFIED SOLUTION
Avatar of JS List
JS List
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JS List

ASKER

Solved the problem