Note that there are some explanatory texts on larger screens.

plurals
  1. POWebClient.DownloadFile File Corrupt
    primarykey
    data
    text
    <p>I'm trying to download files directly from a list of urls.</p> <p>I was able to download most files successfully except for the <em>.docx</em>. I was able to download the <em>.docx</em> file, but when I try to open it, the error message shows that <code>"The file is corrupt and cannot be opened"</code>, when I try to repair it with Microsoft Word, I got another error message saying <code>"Microsoft Office cannot open this file because some parts are missing or invalid"</code>. I don't have any issue when download <em>pdf</em> files.</p> <p>My code is very simple and it looks like this:</p> <pre><code>WebClient webClient = new WebClient(); webClient.DownloadFile("http://somehost/somefile.docx", "C:\\somefolder\\somefile.docx"); webClient.Dispose(); //I added this line just to see if it will fix the problem but no it didn't </code></pre> <p>I went to the urls in the browser and make sure that the files does exist and are not corrupted. The urls are just fine and I was able to download files directly from the urls in a browser and the file opens.</p> <p><strong>Additional Information:</strong></p> <p>I did find one thing that's different for pdf url and docx url, but I really don't think it has anything to do with my problem. When I go to the pdf url in a browser, the <em>pdf</em> was displayed in the browser. However, when I go to the docx url, the page doesn't show anything, but the download for the file automatically starts. I don't think this will make a difference but just FYI.</p> <p><strong>EDIT 10:38AM</strong></p> <p>I just tried the Async method. I was able to download the docx file and open it, but it appear as a blank word document, which is still not correct. The same docx file I download from the browser does have content.</p> <pre><code>webClient.DownloadFileAsync(new Uri("http://somehost/somefile.docx"),"C:\\somefolder\\somefile.docx"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload