Click here to Skip to main content
15,917,964 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having both Ms Office and OpenOffice.
I have Called Excel by "EXCEL.EXE" by using System.process.Start
and now I want to Check if My system doesnot have Ms Office then it should call Spreadsheet.

.xls is my file extension.

Various way you can check that ms excel is installed or not.
I way is

public bool IsMsExcelInstalled(){
   RegistryKey key = Registry.ClassesRoot;
   RegistryKey excelKey = key.OpenSubKey("Excel.Application");
   return excelKey == null ? false : true;

Another way

public bool IsMsExcelInstalled(){
  Type excel = Type.GetTypeFromProgID("Excel.Application");
  return excel !=null;

Based on MS Excel installed you now can take decision to run open office.
Share this answer
MalwareTrojan 19-Feb-13 4:49am    
And now, how can we open that file in OpenOffice Spreadsheet in asp.Net?

.xls in my file extension
S. M. Ahasan Habib 19-Feb-13 4:53am    
I never work with OpenOffice spereadsheet. But the way you luch ms excel same way you can lunch OpenOffice. Just you find out what the main executable file name and location, After getting that you send that path to the System.Process.Start methods as argument.
MalwareTrojan 19-Feb-13 5:53am    
hey Sorry the Requirement has slidely changed...

I have Called Excel by "EXCEL.EXE" by using System.process.Start
and now I want to Check if My system doesnot have Ms Office then it should call Save in the same file extension format without any option.

.xls is my file extension.
if excel not instaled then i guess you want to store/download that file. If so then
if (!IsMsExcelInstalled()){
 //assume fileFullName will be the file path which need to store/download.
  var fileInfo = new FileInfo(fileFullName);
            string fileName = Path.GetFileName(fileFullName);
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
            HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            HttpContext.Current.Response.ContentType = "application/octet-stream";

You you want to download other file types then you need to change the value of
property. for example if you download pdf file then the value will be
If it is doc file then
value will be "Application/msword".
Share this answer
MalwareTrojan 21-Feb-13 1:45am    
The above code is running successfully for .xls but i even want to download .pdf,.doc,.cvs
S. M. Ahasan Habib 21-Feb-13 2:21am    
update solution. You just read it again.
MalwareTrojan 21-Feb-13 2:43am    
But i had searched that "octet-stream" works for all file extensions. . . . still it just works for .xls file with Ms Excel

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900