cURL / Mailing Lists / curl-library / Single Mail


Fwd: Downloaded File (.pdf) Corrupt

From: Eric Belec <>
Date: Sat, 7 Jan 2012 15:11:28 -0500

  libcurl (.net) with C# :

I determined that 9 out of 10 times downloading my various pdf files
will work. The problem is the 1 of 10 times where the pdf returned was
22kb (and corrupt) instead of a working pdf of size 40kb...

Please let me know if there is an alternate way I can write my pdf out..
I've spent so much time and I'm at the end of the ropes.. Any help would
be appreciated! Below is the key code areas..

// Code to Download the pdf

                     easy.SetOpt(CURLoption.CURLOPT_URL, linkToPDF); //
    prep for downloading the PDF
                     Easy.WriteFunction wfile = new
    Easy.WriteFunction(OnWriteFile); //attach method for writing to a file
                     easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wfile);

    _binaryWriter = new BinaryWriter(File.Open(savePath, FileMode.Append));_
    _easy.Perform(); // download PDF_
                     binaryWriter.Close(); //close file
                 catch (Exception e)
                     return results =


// Writing to File.. (Potential Problem Area)

    public Int32 OnWriteFile(Byte[] buf, Int32 size, Int32 nmemb, Object

           binaryWriter.Write(buf, 0, nmemb);

                 return size * nmemb;

List admin:
Received on 2012-01-07