Download a File using WebClient class

G

Guest

Hi,
I'll download some file from our client site which is accessed after
logging in through some credentials. There I have the option to download a
file. I'll set it to download, and the download is started message apprears
on the page.
After a while I get an email saying that down load is complete. Then I'll go
back to the same page where I initiated download, I'll have an option to view
downloaded file.
I'll view the file and save the file on to my disk. This is the process I'm
following for a long time. In order to automate the download process I
researched some articles and have developed an asp.net web application using
WebClient.
I'm not sure why it is not working. When I run the application, it should
initiate the download process. But its not doing it.
Am I missing anything here?
This is the code I've written in the application.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;

namespace FileDownload1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

WebClient Client = new WebClient();

NetworkCredential credential =
new NetworkCredential("userid", "pwd", "domain name");
Client.Credentials = credential;

Client.DownloadFile("Url", "C:\file1.xslx");


}
}
}

I'm struggling with this problem for a number of days, please any body help
me.
Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top