Member Avatar for sixtus

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

Recommended Answers

All 4 Replies

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

Member Avatar for sixtus

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.

commented: good catch! +5
Member Avatar for sixtus

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.