0

I open an excel file using c# and it works correctly when I create the file. Then I send (through Internet) the file to someone else to add extra data (basically to fill rows). Then that one sends me the file back. The result is that I cannot open the received file. This code fails:

xlApp = new Microsoft.Office.Interop.Excel.Application();
xlWorkBook = xlApp.Application.Workbooks.Open(PathToFile, System.Reflection.Missing.Value, true); //Read only

It throws an exception:

System.Runtime.InteropServices.COMException: Office detectó un problema con este archivo. No se abra este archivo para ayudar a proteger el equipo.

It is in Spanish, but the translation is something like: Office detected a problem with this file. This file doesn't open to help you protect the PC.

I am a bit lost with this internet protection. Can XML files be dangerous? I created the file without any macro or code. And when reading it I do not need any macro or code to execute. I will just read the text in the cells. So, is there any way to open the file using c# without any risk? I understand that the other end could be mean and add some virus to the file (I don't even know if this is possible) but I just need to open it and read the contents of the cells.

Ton
  • 9,235
  • 15
  • 59
  • 103
  • 1
    Can you at least post the code that you are using. – Richard May 02 '20 at 07:55
  • Since the file is downloaded from the internet, it most likely flagged with the `Zone:Identifier` metadata, see https://stackoverflow.com/questions/6374673/unblock-file-from-within-net-4-c-sharp on how to remove it. – Christian Held May 02 '20 at 09:57

1 Answers1

0

Looks like the file can be opened under the Protected view in Word. Files from the Internet and from other potentially unsafe locations can contain viruses, worms, or other kinds of malware that can harm your computer. To help protect your computer, files from these potentially unsafe locations are opened as read only or in Protected View. By using Protected View, you can read a file and see its contents and enable editing while reducing the risks. Read more about that in the What is Protected View? article.

You may find a similar case Remove protected view from Excel sheet opened programmatically in Access helpful.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45