Not able to Download files using CookieAwareWebClient class through web browser RRS feed

  • Question

  • User953931160 posted

    Hi All,

    I am trying to download files from a site and was downloading from last 1 year but suddenly it stopped downloading the files instead it is downloading the page's HTML content rather than the files. below is the part of my source code which does the downloading part.

    it is a windows application and using web browser i am trying to download files. CookieAwareWebClient is the class in which i have downloadfile method which does it. below mentioned source code demonstrates it.

                    _logObj.Debug("Entered DO.Downloader.DOFileDownload.downloadfile(string _filelink, string fileName3).");
                    if (string.IsNullOrEmpty(pFilelink) || string.IsNullOrEmpty(pFileName3))
                        throw new System.Exception("pFilelink or pFileName3  is not initialized or empty, Please check !");
                    string FilePath = _downloadDestination + pFileName3;
                    CookieAwareWebClient client = new CookieAwareWebClient();
                    client.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                    client.Credentials = CredentialCache.DefaultNetworkCredentials;
                    client.CookieContainer = cookies;
                    client.Headers.Add("User-Agent", "my App");
                  //  client.Headers.Add("Accept", "*/*");
                    HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
                    client.CachePolicy = policy;
                    client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(client_DownloadFileCompleted);
                 //   string content=client.DownloadString(pFilelink);
                    client.DownloadFile(new Uri(pFilelink), FilePath);

    Can any one help me to solve this issue ?


    Santosh Kumar Dash

    Monday, September 1, 2014 4:10 AM