i used following code to download file from secured site but file created on folder @"C:\Downloads\Filename" show HTML tags like This
You are not logged on. Please logon first.
then Actual File content.
try
{
WebClient client = new WebClient();
client.Credentials = new System.Net.NetworkCredential("username", "password");
byte[] pageData = client.DownloadData("url");
string pageHtml = Encoding.ASCII.GetString(pageData);
Console.WriteLine(pageHtml);
client.DownloadFile("url", @"C:\Downloads\071213.ACCT");
}
catch (WebException webEx)
{
Console.WriteLine(webEx.ToString());
if (webEx.Status == WebExceptionStatus.ConnectFailure)
{
Console.WriteLine("Are you behind a firewall? If so, go through the proxy server.");
}
}
You are not logged on. Please logon first.
then Actual File content.
try
{
WebClient client = new WebClient();
client.Credentials = new System.Net.NetworkCredential("username", "password");
byte[] pageData = client.DownloadData("url");
string pageHtml = Encoding.ASCII.GetString(pageData);
Console.WriteLine(pageHtml);
client.DownloadFile("url", @"C:\Downloads\071213.ACCT");
}
catch (WebException webEx)
{
Console.WriteLine(webEx.ToString());
if (webEx.Status == WebExceptionStatus.ConnectFailure)
{
Console.WriteLine("Are you behind a firewall? If so, go through the proxy server.");
}
}

Iftikar HussainPosted Jul 15, 2013, 5:19 AM
Please refer the below link
http://stackoverflow.com/questions/11118712/webclient-accessing-page-with-credentials
Regards,
Iftikar