//获得下载文件的大小
private static long GetFileSize(string url, out bool progressKnown)
{
HttpWebResponse response = null;
long size = -1;
try
{
response = (HttpWebResponse) GetRequest(url).GetResponse();
size = response.ContentLength;
}
finally
{
if(response != null)
response.Close();
}
return size;
}
//下载请求
private static HttpWebRequest GetRequest(string url)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
return request;
}