im trying to download a file ... when i use this code first

response.AddHeader("Content-Disposition", "attachment;filename=\"" + Server.MapPath(strURL) + "\""); 
byte[] data = req.DownloadData(Server.MapPath(strURL));

it shows the error

" The name 'Server' does not exist in the current context d:\proj\fledwnld\fledwnld\Form1.cs "

then i do google search regarding this and got into use the above code like this,

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Web; 
using System.Web.UI.WebControls; 
using System.Net; 
 
namespace fledwnld 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
 
        private void button1_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                MessageBox.Show("Downloading file"); 
                string strURL = textBox1.Text; 
                WebClient req = new WebClient(); 
                HttpResponse response = HttpContext.Current.Response; 
                response.Clear(); 
                response.ClearContent(); 
                response.ClearHeaders(); 
                response.Buffer = true; 
              [B]
                response.AddHeader("Content-Disposition", "attachment;filename=\"" +   System.Web.HttpContext.Current.Server.MapPath(strURL) + "\""); 
                byte[] data = req.DownloadData(System.Web.HttpContext.Current.Server.MapPath(strURL));     [/B]         
                response.BinaryWrite(data); 
                response.End(); 
            } 
            catch (Exception ex) 
            { 
                Console.WriteLine(ex); 
            } 
 
        } 
    } 
}

Now im not getting errors, but i ve got no File Download dialog pop ups, it also doesnt show any exception.. what i am doing wrong?

You can't use intrinsic page (asp.net) object in your win app.

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.