| Author: Payal Jain 31 Jul 2008 | Member Level: Gold | Rating: Points: 5 |
i know how to download but my code doesn't promt for destination location....it is fixed...
add this line at the top of ur code file
using System.Net;
and this code for the click event of link button for file
protected void LinkButton1_Click(object sender, EventArgs e) { WebClient client = new WebClient(); client.DownloadFile(@"http://noeld.com/dl.asp?filename=upload.zip&country=USA,", @"G:\Some Usefull software\upload.zip"); }
|
| Author: VijayaShankar 31 Jul 2008 | Member Level: Gold | Rating: Points: 6 |
The sample code is attached.
<%@ Page Language="C#" %> <%@ Import Namespace="System.IO" %>
<html> <head> <title>C#: File download</title> <script runat="server"> void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack){ Response.ContentType="application/ms-word"; Response.AddHeader( "content-disposition","attachment; filename=download.doc"); FileStream sourceFile = new FileStream(@"F:downloadexample.doc", FileMode.Open); long FileSize; FileSize = sourceFile.Length; byte[] getContent = new byte[(int)FileSize]; sourceFile.Read(getContent, 0, (int)sourceFile.Length); sourceFile.Close();
Response.BinaryWrite(getContent); } } </script> </head> <body> <form runat="server" id="frmDownload"> <asp:button id="btnDownload" Text = "Click here to download" runat="server" /> </form> </body> </html>
|
| Author: Payal Jain 31 Jul 2008 | Member Level: Gold | Rating: Points: 6 |
try this
private void DownloadFile( string fname, bool forceDownload ) { string path = MapPath( fname ); string name = Path.GetFileName( path ); string ext = Path.GetExtension( path ); string type = ""; // set known types based on file extension if ( ext != null ) { switch( ext.ToLower() ) { case ".htm": case ".html": type = "text/HTML"; break; case ".txt": type = "text/plain"; break; case ".doc": case ".rtf": type = "Application/msword"; break; } } if ( forceDownload ) { Response.AppendHeader( "content-disposition", "attachment; filename=" + name ); } if ( type != "" ) Response.ContentType = type; Response.WriteFile( path ); Response.End(); }
|