http download  
Author Message
MiteshSura





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();

try

{

//string parentLink = TextBox_ParentLink.Text;

string series = TextBox_Series.Text;

string type = DropDownList_Type.SelectedItem.Text;

conn.Open();

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 ;

Response.Redirect(url);

}

else

{

lblError.Text="Invalid Trustee Site";

}

//Response.Redirect(" http://www.hide-link.com/ ;);

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

finally

{

conn.Close();

}

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  
 
 
timvw





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...


 
 
RizwanSharp





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

Hi,

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("http://www.jpmorganchase.com/pdfdoc/jpmc/ir/financial/abs/autofin/03adec06.pdf", "03adec06.pdf");

}

For

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,

HTH,