http download  
Author Message

PostPosted: .NET Framework Networking and Communication, http download Top

dear All ,

I am trying to download a file from Web Server to my local machine.

I am using .Net Framework 1.1 and Visual Studio 2003

this is snipet of code I have used.

private void Button2_ServerClick(object sender, System.EventArgs e)


string connString = "Data Source=cdodev;User Id=security;Password=security;Integrated Security=no;";

OracleConnection conn = new OracleConnection(connString);

DataSet ds = new DataSet();



//string parentLink = TextBox_ParentLink.Text;

string series = TextBox_Series.Text;

string type = DropDownList_Type.SelectedItem.Text;


string dataString = "select b.url from tbl_crawler b where b.parentlink = '" + TextBox_ParentLink.Text.Trim() + "'";

OracleCommand cmd = new OracleCommand(dataString, conn);

cmd.CommandType = CommandType.Text;

OracleDataReader dr = cmd.ExecuteReader();

if (dr.Read())


// C# retrieve the first column in the select list

string parentLink = dr.GetString(0);

string url = parentLink + series + "." + type ;





lblError.Text="Invalid Trustee Site";


//Response.Redirect(" ;);


catch (Exception ex)








This will capture allias from user and from the backend get the actual url.

This is working fine for non-password sites,most of the sites are password protected , and I want to automate

download from this sites. I have the legal UserName and password of the Sites.

.NET Development22  

PostPosted: .NET Framework Networking and Communication, http download Top

You could perform a WebRequest (and use the crendentials) and pass the retrieved data to the visitor...


PostPosted: .NET Framework Networking and Communication, http download Top

See WebRequest/WebResponse classes in System.Net namespace, This will do what you want.All you need to do is to form your Request well so Server can understand and give you what you need.

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp

Indian Ocean

PostPosted: .NET Framework Networking and Communication, http download Top


Use the following simplest way to download file from URL which requires username/pass too,

private void DownloadFile(string strFileURI, string strFileName)


WebClient client = new WebClient(); //You can have this at class level so dont need to instantiate for each request

//Set username/pass required for a url access

NetworkCredential myCred = new NetworkCredential("UserName","Password","Domain");

client.Credentials = myCred;

client.DownloadFile(strFileURI, strFileName);

//e.g. client.DownloadFile("", "03adec06.pdf");



For more sophisticated APIs you can use WebRequest or HttpWebRequest classes the same way. You can find good samples in MSDN for that. But IMHO, the above code serves the purpose well,