Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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.
Posted 18-Feb-13 22:02pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Vardhan Desai at 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 at 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.
Vardhan Desai at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.Clear();
            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";
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.WriteFile(fileFullName);
            HttpContext.Current.Response.End();
}

You you want to download other file types then you need to change the value of
HttpContext.Current.Response.ContentType
property. for example if you download pdf file then the value will be
HttpContect.Current.Response.ContentType="Application/Pdf"
If it is doc file then
value will be "Application/msword".
  Permalink  
v4
Comments
Vardhan Desai at 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 at 21-Feb-13 2:21am
   
update solution. You just read it again.
Vardhan Desai at 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)

  Print Answers RSS
0 Sascha Lefévre 485
1 Sergey Alexandrovich Kryukov 325
2 Maciej Los 255
3 Abhinav S 185
4 Peter Leow 110
0 Sergey Alexandrovich Kryukov 6,953
1 OriginalGriff 6,311
2 Maciej Los 2,732
3 Peter Leow 2,694
4 Abhinav S 2,652


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100