-1

there's something I don't understand, and I think I need a bit of help on this one...

I'm just trying to open an excel file in read only mode. I see that filestream are able to open a file. But why my excel file is not showing up ? What am I missing ?

Sorry, i'm still new in C#/.NET...

Thanks in advance.

EDIT : I'm using .NET 5

Xariien
  • 3
  • 2
  • Are you wanting to open the Excel file in Excel? FileStream just gives you a way to access the bytes contained within the file. – phuzi Jul 30 '21 at 08:22
  • Yes and if possible...any other files (Like Word, pdf...) with the default application. – Xariien Jul 30 '21 at 08:24

1 Answers1

0

It sounds like you expect to be able to see it as a spreadsheet.

That's not really going to work, any more than opening an executable file will automagically cause it to run.

All opening a file does is give you access to the bytes in the file, those bytes still have to be interpreted somehow.

That's basically what Excel does - it opens the file and reads in the content. It just happens to know what to do with that content to render it to the screen.

If you want to do that yourself, you'll probably need to run Excel, passing the filename as an argument, and hoping there's a way to do that in read-only mode.

Or, as a last resort, make a temporary copy of the file and bring the copy up in Excel, then it most likely won't matter what the user does with that copy, it won't affect the original.


For what it's worth, there is another question here covering the different ways to do that (run a separate executable from with your C++ program). You can find it here.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953