tags:

views:

33

answers:

1

There is an asp.net page receiving some request parameters.

When everything is fine, it returns somehow a file to download.

When not, it inserts an error message into this page.

The file doesn't exists in hard-disk, it will be created by my page.

Do you know how to do that?

EDIT: In fact, the file exists in hard-disk, but it is embedded into another file, a zip file. So I can't just redirect to the file url. I need to unpack the zip file, retrieving the requested file, receiving a output stream.

+2  A: 
 Sub downloadRoutine(ByVal filePath As String)
        Dim fi As System.IO.FileInfo

        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/unknown"
        Response.AddHeader("Content-Disposition", "attachment;filename=" + filePath)

        Try
            Response.WriteFile(fi.FullName)
        Catch ex As Exception
            ex.Message.ToString()
        End Try
        Response.End()
        fi = Nothing
    End Sub

For Unzipping..

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/a343411d-f577-431b-92d7-5792912a7652

Scroll down to Cheeso's entry..

He suggests.. http://dotnetzip.codeplex.com/

madcolor
Replace "Response.WriteFile()" with your own Response.Write() commands and contents.
Joel Coehoorn
ok, thanks, I'll try it ;)
Victor Rodrigues
I'm already using dotnetzip, thanks! It is the best I've found around
Victor Rodrigues