Hello all,

Im sure anybody here can help me.. this is my problem. Im trying to automate downloading a file from a web page. i knew the file name too. But i cant achieve my task.. Really dont know whats the problem. and also dont know what to do. i even tried many of the working samples found while i do googling. But no hope at all.

really getting tired.. im spending more than one week for this to solve a simple task to download a file from a web page using c#.. i ve tried many ways and all i ve got is an exception. pls do help.

Can Any body pls post here an working example to download a file from a web page.. what i need is to login to a website and download a file from that web page using c#. It would be very helpful if u do post some working example here.


Thanks in advance.

Comments
Do not flood the forum by posting the same question more than once (ie in multiple forums).

sorry all,
i ve found my problem.. i ve given my ip address wrongly.. so only i was getting exception.. Now the file get downloaded.. but the problem now is if i download a file in second or other page of the website programmatically.. when i view the downloaded file in local drive it shows the login page of that site only. for example,

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.Net; 
using System.IO; 
namespace WindowsFormsApplication4 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
            WebClient Client = new WebClient(); 
            WebProxy proxyObj = new WebProxy("http://ipaddress:port"); 
            proxyObj.Credentials = CredentialCache.DefaultCredentials; 
            Client.Proxy = proxyObj; 
            Client.Credentials = new NetworkCredential("user", "pass"); 
                     
            Client.DownloadFile("http://www.codeguru.com/csharp/.net/net_asp/article.php/c17151/Images-on-the-Fly-in-ASPNET.htm", @"d:\aa.html"); 
            MessageBox.Show("done"); 
        } 
     } 
}

i ve found the login page of codeguru.com in my 'd' drive.. whats the problem.. what i ve to do to get the exact file.

Hi
Actually it is a simple task. Just add your files to a folder called "downloads". Then in drag and drop a hyper-link into your form. Set the properties, and give the file which is in you downloads folder. The browser will automatically shows the popup window.

any doubts ask me.

Comments
You know why

sorry to ask u so,

i cant understand your point.. can u pls be a bit elaborate?

really sorry.

can anybody help..
pls..

im getting again and again the same login page only whenever i download.. i dont know how can i get the file i want to download pls do help.. its urgent.. pls..

the page i ve got when i execute the above mentioned code is

Attachments

hello all,

i need help.. im trying to download a file from a website.. but whenever i tried to download a file the login page of that website gets downloaded.. the file i found in my local drive only contains the login page of that site.. how can i get the file what i wnt to download..

pls do help..

im using code something 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.Net; 
using System.IO; 
namespace WindowsFormsApplication4 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
            WebClient Client = new WebClient(); 
            WebProxy proxyObj = new WebProxy("http://ipaddress:port"); 
            proxyObj.Credentials = CredentialCache.DefaultCredentials; 
            Client.Proxy = proxyObj; 
            Client.Credentials = new NetworkCredential("user", "pass"); 
                     
            Client.DownloadFile("http://www.codeguru.com/csharp/.net/net_asp/article.php/c17151/Images-on-the-Fly-in-ASPNET.htm", @"d:\aa.html"); 
            MessageBox.Show("done"); 
            
        } 
       
    } 
}

I've tried that code and its working fine. Why are you using a proxy?

Thanks

since im getting exception for all application i ve tried

The remote server returned an error: (407) Proxy Authentication Required

i ve started using proxy.

u tried the code which i gave here?[that codeguru example].
is it working for u?

I've tried that code and its working fine. Why are you using a proxy?

Thanks

u tried without proxies?

which code u ve tried?

if it works fine for u can u pls post the code here which works for u..

pls..

Yeah, its working without the proxy.

This code works fine for me:

WebClient Client = new WebClient();

Client.DownloadFile("http://www.codeguru.com/csharp/.net/net_asp/article.php/c17151/Images-on-the-Fly-in-ASPNET.htm", @"d:\abc.html");

MessageBox.Show("done");

k.. u didnt even give the username and password?

i dnt know whats happening in my system and y its not functioning?

Do u know any reasons y im getting like this..

i cant proceed to the next step.
pls help.

This article has been dead for over six months. Start a new discussion instead.