Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with file download

Status
Not open for further replies.

tsp1lrk72

IS-IT--Management
Feb 25, 2008
100
US
Hello-
for some reason, my file download is not working correctly- I'm creating folders dynamically on the server based on the ID of the record, that is fine, I have a button with the following code:

Code:
 FuelSurchargeID = Request.QueryString("FuelSurchargeID").ToString
        Dim root As String = "D:\Staging\secure\memnet\fuel_surcharge\attachments\" & FuelSurchargeID & "\"
        Dim files() As String = Directory.GetFiles(root)
        Dim sb As New StringBuilder(2048)
        Dim f As String
        Dim type As String = ""
        For Each f In files
            Dim filename As String = Path.GetFileName(f)
            Dim ext = Path.GetExtension(f)
            Response.Clear()
            Response.ContentType = "application/octet-stream"
            Select Case ext
                Case ".htm", ".html"
                    type = "text/HTML"
                Case ".txt"
                    type = "text/plain"
                Case ".pdf"
                    type = "Applicaton/pdf"
                Case ".doc", ".rtf"
                    type = "Application/msword"
                Case ".csv", ".xls"
                    type = "Application/x-msexcel"
                Case Else
                    type = "text/plain"
            End Select
            Response.AddHeader("Content-Disposition", _
            "attachment; filename=""" + filename + """")
            If type <> "" Then
                Response.ContentType = type
            End If
            Response.Flush()
        Next

The file downloads, but when I open it (say MS Word) It asks for the stylesheets and then-- I click no, then it actually loads the page, not the file-- what is wrong?

Thanks!
 
There are two problems that stand out quite a lot. The first is that you are trying to send multiple files in a request which you cannot do. The second is that you are not actually sending any file! All you have done is added a response header and flushed the response but nowhere have you actually sent the actual file (look up the Response.WriteFile method).


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Okay, I'll take a look, Thanks for the pointers.
 
I got it-- I forgot to Response.Write the file-

Thanks for the tip...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top