Click here to Skip to main content
15,220,538 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear all,

In my Windows application I am using WebClient DownloadFile method to download several PDF files from a server on local network.

Each file is a report that gets generated when its URL is called. Reports are of different sizes and take different periods of time to get generated.

My code loops through a list of URLs (about 400), and for each URL it calls DownloadFile method, and the corresponding report is generated and downloaded to local machine. URLs are definitely correct.

The problem is that almost each time the application is run, some of downloaded files are damaged, only 7KBs are downloaded (I think it’s for meta data), and Acrobat Reader gives me a message when I try to open the file:
“…it’s either not a supported file type or because the file has been damaged…”

It’s not always the same files that get damaged, and when I re-run the application, those files often succeed, and some others might fail… it seems to be random and I can’t find out the criteria.

Note 1: I don’t want a file to start download until its precedence is completely downloaded, that’s why I am not using the asynchronous method.
Note 2: All files are Oracle reports and get generated by querying a database.
Note 3: No EXCEPTION is thrown in case of damaged files.

Thanks in advance.
Posted
Updated 9-Jun-13 9:08am
v4
Comments
   
There are too many ways to screw up things, even, apparently, to damage files. Who can we see the reason for the damage without seeing any code?
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 1

Dear Sergey, this is my code. it's simple.


using ( WebClient client  = new WebClient() )
{
    for(int i=0; i< URL_List.Length; i++)
    {
        try
        {
        client.DownloadFile( URL_List[i] , myLocalPath+fileName+".pdf" );
        }
        catch(Exception x)
        {
         // write exception message to error log...
        }
    }
}
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

I have figured out the problem. Some reports are just not generated correctly -for some reason- and hence, an HTML page with error message is returned instead of PDF file, so it's not a supported file type that can be opened by acrobat reader. When i changed "damaged" files extension from .pdf to .html , they opened in the browser and i could read the error returned by Oracle.
thank you everyone.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100