Cannot open .xls file after Office update - c#

I am not able to open .xls file after last Excel update. When I double click on file, Excel starts but do not show any message.
In the past it showed "The file you are trying to open, 'filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?" and I was able to open it.
I am generating this file with C# and xsl stylesheet. When I open file in Notepad++, add space somewhere and save it - file is suddently possible to open.
How to fix this? Where can be a problem?
Thank you for help.

Related

Include and launch PDF from C# Visual Studio Project

In my C# application i have a help button. When it's pressed I would like for the application to open up a PDF file in the systems default PDF reader, something I can do with a command like Process.Start("pathToPDF").
The problem is that I would like to include the PDF as a resource instead of calling an external file. I do not wish to copy the PDF to the users computer and do not want to host it online or on a NAS.
Right click on your project in the Solution Explorer, then add existing file and choose your pdf (if you cannot find it, make sure you are showing all files and not just .cs files etc.).
Click on the newly added item once in the solution explorer and in the properties window, you set Copy to Output Directory to Copy Always or Copy if newer.
Now you can open the pdf file as expected using Process.Start(filename.pdf);
The only Secure way to show a PDF without providing a file is to include your own Viewer Component (Ex. http://www.o2sol.com/pdfview4net/overview.htm)
Some components allow to load a PDF from Memory (as in a embedded Resource) directly into your Viewer Component, another way would be to create an encrypted binary file to ship with your application and encrypt/load when necessary.
As soon you want to show the PDF in an external viewer ,be aware that the User will have the ability to save the PDF anyway.
Maybe you can explain your reasons to not want to include the file, so we can suggest other solutions to you?
Update:
As noted in your comment, the goal is to have a clean installation.
It would be possible to embed the File as a resource, but then you would
have the problem that if you extract the file temporarily to display it, you can't really control the clean-up of that file, because it's locked by the PDF Reader Application.
So you would end up with the PDF File anyway ;)
What you can do to keep your Application Folder cleaner, is to not install the PDF under that Application Folder but under the "Common Documents" Directory.
For Example: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "MySoftware", "Help.pdf")
Which normally targets: C:\Users\Public\Documents\MySoftware\Help.pdf

How to programmatically restore the XLS file that was modified by a thirdparty tool

We are in the process of migrating the documents from AppXTender ( a EMC Documentum tool ) to another system.
I took a XLS file from AppXtender physical store ( the tool have renamed the .XLS file to .BIN ) and I knew its an excel file I tried renaming it to .XLS but the file is not opening as excel.
I learnt that the file is been modified by the AppXtender with some content like, "FFL 1.0 followed by the original file name.XLS".
When I open the excel in a notepad I could see this in the first line and there are couple of more lines with some text like "Embedded" and with some number.
If I manually remove those lines and save the file and still the file is not opening as excel.
What are these custom texts? how do i programmatically (C#) remove them from the excel file and restore as the proper excel file?
Thanks!
Karthik

Converting any file to .xlsx leads error in opening it

I am saving as any file to .xlsx format. If the original file is not with .xlsx extension, it is throwing exception while trying to open it. The exception message is :-
Excel cannot open the file 'abc.xlsx because the file format or file
extension is not valid. Verify that the file has not been corrupted
and that the file extenstion matches the format of the file.
Whereas if conversion is in .xls format, I can open the converted file with warning message.
The file you are trying to open, abc.xls, is in a different format
than specified by the file extension. Verify that the file is not
corrupted and is from a trusted source before opening the file. Do you
want to open the file now?
I need to convert file to .xlsx format by C# code regardless its extenstion and open it by Excel 2010.
Thats not how file-types work!
You can not simply rename a file and it gets converted to a different type.
Renaming *.xls to *.xlsx works, because both are Excel files which can be opened by MS Excel, but for all other types (except some other which Excel can handle, like e.g. *.csv) you need to read the file and "manually" convert them.
To write *.xlsx using C# you can use e.g. EPPlus (NuGet).
You need a library that convert the files for you.
I see that you need to open files from Office 2003, so you need to use something like NPOI
Unfortunately, even if EPPLUS is a great library for Office's files, it only support the OXML Documents like .xlsx or .docx but not the .xls.
NPOI is a free opensource library to work with Office 2003->2010/3 files.
Here is the link

Opening a MS .dot file through ASP.Net application

I have an application that when run in debug on my local machine has no problem opening this .dot file. But I've copied my application to a live server and when testing the app I get the following error message when trying to open the .dot file. This file is generated on a button click event and copies information from the system and pastes it into bookmarked sections on the template. The error is-
"ERROR: Cannot generate call sheet - Word was unable to read this document. It may be corrupt. Try one or more of the following: * Open and Repair the file. * Open the file with the Text Recovery converter."
The server has MS Word 2007 installed. Has anyone ever experienced this before, or are there any known workarounds that will correct this for me?

export XML -> Excel

I'm already generating an excel XML file (.xml) containing 2 worksheets.
issue #1:
the people downloading the XML file wouldn't know to open the file in Excel. (they'd complain.)
solution #1:
I rename the file to .XLS instead of .XML.
issue #2:
when opening the file in Excel i get the this error:
The file you are trying to open, ‘XXX.xls’ is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file.
Solution #2:
Convert the XML file to XLS file somehow.
so here's where i turn to you...
Goal:
they need to be able to open the file by double-clicking it.
i don't want to have to rebuild the excel file using some 3rd party library.
Ideas:
perhaps convert XML to xls using tools like the following:
http://npoi.codeplex.com/
http://excelpackage.codeplex.com/
I'd need some sample code of the simplest and LITEst way of achieving this.
any other ideas?
Just a random thought: if you're generating XML for people to open with Excel, why not generate XSL (or maby XSLX) in the first place?

Categories