locked
downloading file that is "damaged" RRS feed

  • Question

  • I am currently using a webclient in vb.net to download an Excel file and save it as a PDF. When I run the program I don't get any errors and it appears to work fine, however, when I go to open the file it says "could not open file because it is either not a supported file type or because the file has been damaged" 


    Tuesday, June 18, 2019 12:23 PM

All replies

  • Well without seeing your code it's impossible to assist.

    Here are examples and documentation to work from.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/computer-resources/how-to-download-a-file

    https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=netframework-4.8

    https://www.vb-helper.com/howto_net_download_file.html

    If they are not helpful then show your code. Also try downloading the file without code and see if the file is actually valid.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, June 18, 2019 12:37 PM
  • When I download the file without code, I get the following error in Excel: "The file format and extension of 'download.xls' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?" If I click "Yes," the file opens fine, and I can download it as a PDF from excel. However, when I try to code this in vb I believe the error message is what is causing the file to not open correctly. Is there a way to code in vb to click "yes" on this error message in excel?


    • Edited by Lyvia H Tuesday, June 18, 2019 12:48 PM
    Tuesday, June 18, 2019 12:46 PM
  • When I download the file without code, I get the following error in Excel: "The file format and extension of 'download.xls' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?" If I click "Yes," the file opens fine, and I can download it as a PDF from excel. However, when I try to code this in vb I believe the error message is what is causing the file to not open correctly. Is there a way to code in vb to click "yes" on this error message in excel?


    So this means either the file is bad or the extension is wrong, try using .xlsx file extension.

    Note when Excel sees a problem and are prompted to open Excel will sometimes be able to correct the issue itself.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, June 18, 2019 1:16 PM