How to download a file.?

liunx

Guest
hai every one
What is the proper and sure shoot way to down load any file......?
I know that if we use Response.Redirect("filename.file_extension")
it gives u a option to save the file at the client side but ....
if the file extension are like .xml or .htm which can be shown inside the browser the rather than asking for option to save it directly shows the file in the browser (i am talking about IE 5 )

so can any one tell how to Download a file properly.....?
thanks in advance

keep smiling
austinYou can send an http header. You can even have people Download .aspx files that way, or .config files, so on and so fourth.


<%@ Import Namespace="System.IO"%>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

Dim root As String = "C:\temp\"
Dim filepath As String = Request.Params("file")
If Not filepath Is Nothing Then
If File.Exists(filepath) And filepath.StartsWith(root) Then
Dim filename As String = Path.GetFileName(filepath)
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.Flush()
Response.WriteFile(filepath)
End If
End If

End Sub
</script>


<!-- m --><a class="postlink" href="http://www.ondotnet.com/pub/a/dotnet/2002/04/01/asp.htmlHi">http://www.ondotnet.com/pub/a/dotnet/20 ... asp.htmlHi</a><!-- m -->, I have problem opening the file directly into the Browser, ie, I want to skip the Save As dialog. I read from various articles that I should use inline instead of attachment in


Response.Clear()
Response.ContentType = "application/msword"
Response.AddHeader("Content-Disposition", _
"inline; filename=""" & filename & """")

Subsequently, I read that the browser must know the size of the file first, so

Response.AddHeader( "content-length", tStr.Length.ToString())

where tStr is the StringBuilder() created
objStreamReader = File.OpenText("c:\file.htm")
tStr.Append(objStreamReader.ReadToEnd())
objStreamReader.Close()

However, the browser still comes up withthe save as dialog. Does anyone knows how to bypass this correctly?if the browser is not set to handle that file type the save as dialog must come up.
 
Back
Top