Below is the code sample.
============================================================================ using Microsoft.Office.Interop.Excel; using Excel = Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices;
Excel.Application m_ExcelApplication = new Excel.Application(); m_ExcelApplication.Visible = false; m_ExcelApplication.UserControl = false; m_ExcelApplication.Application.ScreenUpdating = false; m_ExcelApplication.DisplayAlerts = false; string strFileName = @"d:\testing\testing.xls";
Excel.Workbook m_ExcelWorkBook = m_ExcelApplication.Workbooks.Open(strFileName, //FileName 2, //UpdateLinks bReadOnly, //ReadOnly Type.Missing, //Format Type.Missing, //Password Type.Missing, //WriteResPassword true, //IgnoreReadOnlyRecommended Type.Missing, //Origin Type.Missing, //Delimiter false, //Editable Type.Missing, //Notify Type.Missing, //Converter Type.Missing, //AddToMru Type.Missing, //Local Type.Missing //CurruptLoad );
===============================================================================
When executing the Open function. I received the following exception:
Microsoft Office Excel cannot access the file 'd:\testing\testing.xls'. There are several possible reasons:
The file name or path does not exist. The file is being used by another program. The workbook you are trying to save has the same name as a currently open workbook.
However, when I removed the directory information and just give it the file name: 'testing.xls' - I putted testing.xls in to the same directory as the Windows Service- everything works fine.
Please help.
Any help will be greatly appreciated.
Thanks
Research shows that automation is an issue with Windows Server 2008, specifically the 64-bit version. The 32bit version works, as well as windows 2003 32/64bit. I'm unsure as to whether it affects only SERVICES or APPLICATION automation as well.. We use a service for our tasks.
Recently we have run into this problem, and it's pretty important. We do some high dollar work using excel automation, and have recently obtained a new system running windows server 2008, just to find out there seems to be a bug/issue that prevents our application from doing its core work.
If you have found a solution please let me know.
It seems that even if you impersonate the service, or assign a specific user to it, or impersonate Excel with DCOM, when the Excel object is instantiated it still uses the Local System as its security profile. Because of this, it uses the registry hive of the Local System and it ends up with properties like StartupPath = "C:\windows\system32\config\systemprofile\AppData\Roaming\Microsoft\Excel\XLSTART", etc..
Now, open up REGEDIT and navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18\ProfileImagePath and make a backup of its value. Next from within the ProfileList registry hive, locate a valid desktop user profile (it should start with S-1-5-21-[xxxx]). Copy the value for its ProfileImagePath and overwrite the one assigned to the Local System profile. Restart your system before trying out the solution.
Note, however, that this is a "registry hack" and I discourage sticking to it. I'm still looking for an alternative solution, so please post your ideas here too if you have them.
HTH
-jeric
Update:
There is a better solution than the registry hack I mentioned above. It still involves fooling the system profile into acting like a user profile.
Please follow Ogawa's solution here: http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91?prof=required
- Edited by angerico Monday, June 29, 2009 7:41 AM
try your solution i still getting error..
iam windows 7 and visual studio c# 2008
- Proposed as answer by D2BII Friday, March 12, 2010 4:52 PM
- Create a regular 32 bit VBS file that creates your Excel object doing whatever it is you need to do with it.
- Create a batch file that executes that file in a 32bit process. Here's how:
- Create a filename (whatever) .bat
- Put the following in the .bat file - > C:\Windows\Syswow64\wscript.exe "C:\<path to your file>\<your filename>.vbs" (or whatever drive or UNC path you need). This tells Windows to run your script as a 32Bit process.
- Install MS Excel only with the absolute minimum of features.
- Run the batch file.
- Edited by D2BII Friday, March 12, 2010 5:00 PM greater clarity
Can you give me more info on this .vbs file. I am trying to work on MS Excel Upload on a Win 2008 IIS7 server . From Visual Studio it works but when I deploy I started getting the errors. I tried Registry hack, no luck. The latest error I see is
There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook.
Hi,
What do you mean with "Now, open up REGEDIT and navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18\ProfileImagePath and make a backup of its value"? A backup, for what?
This is value we have to change, isnt it?
Thanks in advance,
Mónica.
Hi Aeshwar,
Did you ever find a solution to this, i'm running the same spec as you Windows 2008 and IIS7.
Thanks
Johan
Please make this folder.
C:\Windows\SysWOW64\config\systemprofile\Desktop
Windows 2008 Server x86Please make this folder.
C:\Windows\System32\config\systemprofile\Desktop
- Proposed as answer by Debarchan Sarkar - MSFT Wednesday, June 06, 2012 11:23 PM
Thanks. It worked for me.
- Proposed as answer by Ganov Thursday, November 29, 2012 9:15 PM
Hi,
We have Windows Server 2008 R2 64 bits and we are having the same problem... reading this blog i could not guess what was the solution some say to work :S
Can you help me?
Can somebody please share the solution for this issue?
I am facing similar issue with Windows 2012 R2 x64 OS and Excel 2007(32-bit) combination.
I tried couple of things like Excel is able to Open an existing workbook on my system but fails to
create a new Workbook as done by invoking the "Add" command. It fails with Error 800a03ec.
I tried creating the two folders i.e. C:\Windows\SysWOW64\config\systemprofile\Desktop & C:\Windows\system32\config\systemprofile\Desktop, but could not get it working.
- Edited by aksjain Tuesday, April 07, 2015 8:51 AM
Please make this folder.
C:\Windows\SysWOW64\config\systemprofile\Desktop
Windows 2008 Server x86Please make this folder.
C:\Windows\System32\config\systemprofile\Desktop
Hello everyone,
I have the same problem under Server 2012 R2, but creating C:\Windows\SysWOW64\config\systemprofile\Desktop didn't help. I also checked the box "Run with highest Privileges".
Could anybody help me?
Thanks in advance!