c# - WebClient.DownloadFile File Corrupt -
i'm trying download files directly list of urls.
i able download files except .docx. able download .docx file, when try open it, error message shows "the file corrupt , cannot opened"
, when try repair microsoft word, got error message saying "microsoft office cannot open file because parts missing or invalid"
. don't have issue when download pdf files.
my code simple , looks this:
webclient webclient = new webclient(); webclient.downloadfile("http://somehost/somefile.docx", "c:\\somefolder\\somefile.docx"); webclient.dispose(); //i added line see if fix problem no didn't
i went urls in browser , make sure files exist , not corrupted. urls fine , able download files directly urls in browser , file opens.
additional information:
i did find 1 thing that's different pdf url , docx url, don't think has problem. when go pdf url in browser, pdf displayed in browser. however, when go docx url, page doesn't show anything, download file automatically starts. don't think make difference fyi.
edit 10:38am
i tried async method. able download docx file , open it, appear blank word document, still not correct. same docx file download browser have content.
webclient.downloadfileasync(new uri("http://somehost/somefile.docx"),"c:\\somefolder\\somefile.docx");
thank trying help, appreciate it.
i realize problem me not concatenating url correctly. right, stupid mistake made...
webclient didn't throw error incorrect format (for whatever reason), , log file not logging actual url trying connect to, didn't realize doing wrong thing.
anyway, thank , comments me figure out problem was.
Comments
Post a Comment