Hi - I need some help.

I have upgrated my server, webserver, ... to windows 2008, IIS 7.0 and ASP.NET 3.5. That gives me some problems.
I have a page where people can upload and download documents. Upload works fine but download doesn't work.
The documents is downloaded by using a hyperlink with link download.aspx?file=test.txt where test.txt is the document, that is placed in a folder on the web-server.
The importent code in download.aspx is:

Dim filename As String = Path.GetFileName(filepath)
Dim filepath As String = Server.MapPath(Request("file"))
Dim file As System.IO.FileInfo = New System.IO.FileInfo(filepath)

Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Length", file.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment; filename=""" & file.Name & """")
Response.Flush()
Response.WriteFile(filepath)
Response.End()

I worked fine before upgrading, but the "Save/Open"-window opens correctly, but when I click the Save- or Open-button it lookes like download is started but nothing happens. The statusbar doesn't change.

Hope someone can help me.
Thanks

Try this:

Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Length", file.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment; filename=""" & file.Name & """")
Response.WriteFile(filepath)
Response.Flush()
return

What you have looks like it should work but I usually dont clear/force data in/out of the buffered io stream

Thanks - It worked

SORRY NO

I did not work. It worked on the first document I downloaded, but when I tried again I got the same result as described above.

So I am still looking for help.

Dim filename As String = Path.GetFileName(filepath)
Dim filepath As String = Server.MapPath(Request("file"))
Dim file As System.IO.FileInfo = New System.IO.FileInfo(filepath)

In the above code segment, You have used the variable filepath before it is declared in the second statement. How did you compile your code without any errors?

Can you post complete code.

Comments
good catch!

Sorry - that was an copy-paste error.
Dim filename As String = Path.GetFileName(filepath)
is line 3 in my aspx-file.
So that is not the problem.

This article has been dead for over six months. Start a new discussion instead.