Downloading File from Server to Client in asp.net
hello everybody
i have a asp.net web application running on my IIS server.now when a client machine on the local network connects to the server and tries to download a file the file gets downloaded on the server instead of the client mahcine.on my server i have the following code for downloading file
imports System.net
dim wc as webclient
wc=new webclient
wc.downloadfile("http:\\localhost\Download\test.txt","c:\test.txt")
i want the test.txt to be saved on the c: drive of client machine however right now it is getting saved on the server.plz tell me how do i sort this out.
thanx
parth
Re: Downloading File from Server to Client in asp.net
VB Code:
Dim FilePath As String = strFileName
Dim TargetFile As New System.IO.FileInfo(FilePath)
' clear the current output content from the buffer
Response.Clear()
' add the header that specifies the default filename for the Download/
' SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + _
TargetFile.Name)
' add the header that specifies the file size, so that the browser
' can show the download progress
Response.AddHeader("Content-Length", TargetFile.Length.ToString())
' specify that the response is a stream that cannot be read by the
' client and must be downloaded
Response.ContentType = "application/octet-stream"
' send the file stream to the client
Response.WriteFile(TargetFile.FullName)
' stop the execution of this page
Response.End()
You cannot specify where this will get saved, it is at the discretion of the user.
Re: Downloading File from Server to Client in asp.net
So you would place that in a page's codebehind and call that page like
Response.Redirect("Download.asxp?file=abc.txt");