Download file using Webclient shows Wrong Data
hi Guyes,
i used following code to download file from secured site but file created on folder @"C:\Downloads\Filename" show HTML tags like This
<HTML>
<HEAD><LINK rel="stylesheet" type="text/css" name="defaultstyle" href="/cehttp/html/style.css">
<TITLE>Servlet Response Message</TITLE></HEAD>
<BODY>
<H2 align=center><H2>
<HR>
You are not logged on. Please logon first.
<HR>
</BODY></HTML>
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.");
}
}