הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Thursday, February 25, 2010 11:25 AM
Hi,
I need to create an excel file from the database records. I fetched and put the data in an excel file and tried to save that file as follows.
string SavedFileName = Server.MapPath("../NLR/WIP/WIP_" + toDay + ".xls");
excelWorkbook.SaveAs(SavedFileName, Excel.
XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
killExcelProc();
//@@ and released the excell process withthe following function
protected
void killExcelProc()
{
foreach (System.Diagnostics.Process Proc in System.Diagnostics.Process.GetProcessesByName("EXCEL"))
{
Proc.Kill();
}
}
** Now in my XP machine IIS server it is running fine with out any problem. But in windows 2003 Server I am getting the following error
"
**System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file 'D:\RadioSQA\NLR\WIP'. 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. at Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout) at Reports_WIP.btnWIP_Click(Object sender, EventArgs e)
**"
When I opened task manager I didn't find any excel process running. I have given the full permission to the virtual directory (Deployed folder) for ASPNET user. I modified the DCOMConfig configeration (For XP it is ASPNET and for 2003 it is NETWORK SERVICE). I think my application is not being able to save the excel file in the application. But I don't know why.. Please give me light and also tell me what I will have to do.
All replies (39)
Friday, February 26, 2010 4:54 PM ✅Answered
If this running fine on XP , so nothing wrong with your code. May be your windows 2003 server missing some file(s).
kaymaf
If that what you want, take it. If not, ignored it and no complain
CODE CONVERTER SITE
http://www.carlosag.net/Tools/CodeTranslator/.
http://www.developerfusion.com/tools/convert/csharp-to-vb/.
Wednesday, November 3, 2010 11:54 PM ✅Answered | 53 votes
The solution for this appalling BUG in Microsoft IIS & Excel is terrific:
- Create directory "C:\Windows\SysWOW64\config\systemprofile\Desktop " (for 64 bit Windows) or "C:\Windows\System32\config\systemprofile\Desktop " (for 32 bit Windows)
- Set Full control permissions for directory Desktop (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user
"IIS AppPool\DefaultAppPool")
Wednesday, November 24, 2010 2:32 PM
That solution of creating the folder also worked for me. How on earth did you figure that out?
Wednesday, December 22, 2010 6:12 PM | 1 vote
The solution for this appalling BUG in Microsoft IIS & Excel is terrific:
- Create directory "C:\Windows\SysWOW64\config\systemprofile\Desktop " (for 64 bit Windows) or "C:\Windows\System32\config\systemprofile\Desktop " (for 32 bit Windows)
- Set Full control permissions for directory Desktop (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user
"IIS AppPool\DefaultAppPool")
This worked for me as well. In my case the AppPool is running with a domain account identity. I just gave that account full control over the C:\Windows\SysWOW64\config\ systemprofile\Desktop directory that I created.
Thank you!
Thursday, April 14, 2011 4:53 PM
I do not understand this....but it worked!
I have a Excel sheet that opens temporarily before prompting for the actual save. What the Desktop folder has to do with that..dunno?
Thanks!
Thursday, April 14, 2011 5:20 PM
OK, I was so skeptical on this solving it that I almost passed it by.
No idea what, how, or why this has anything to do with it, but it worked for me too.
I am opening an Excel file server-side and then converting it to HTML using automation and .NET
Thank you Bob! Saved me lots of headaches
Wednesday, April 20, 2011 10:21 PM
I tried this and my error went away. But the file still does not open. can you please help.. i have been looking for an answer for a while now and only your have made progress for me..thank you in advance
Friday, April 29, 2011 11:33 AM | 6 votes
I tried that and the error did not go away. However, after using the management console on the server: Start, Run, then type mmc comexp.msc /32 for the 32-bit version.
We are using impersonation in our ASP.NET application, and using a domain user account.
Then selected Component Services, Computers, my computer, DCOM Config, Microsoft Excel Application. Right click, select Properties. On the Security tab, select Customize for Launch and Acitvation Permissions, and add the domain user. Also added the user on the Identity tab, select "This User", and type the user id and password.
After this, and added the aforementioned folder path, Excel worked fine, opening files.
Tuesday, May 24, 2011 10:23 AM
Thank you for this solution, it works great for me. I have just upgraded to Windows 7 and have been pulling my hair out over this for hours!
Tuesday, May 24, 2011 6:50 PM
This solution worked for me as well! Thank You.
Thursday, June 23, 2011 10:58 AM
Great, this worked for me also. Thank you
Thursday, July 7, 2011 7:41 AM
Thank you very much for the solution, it worked like charm for me.....You saved me buddy!
Tuesday, August 2, 2011 4:21 PM | 2 votes
The "tibb" post above got me past the same error, in a windows service that was launching an excel file when I migrated to Windows 7 64 bit from windows XP. Note that the correct answer for most people seems to be the solution I'm referencing, not the one that is highlighted in green for some reason...
Thursday, January 12, 2012 3:20 PM
I have Windows 7 64bit, Excel 2010. This solution worked for me! Thank You.
Monday, April 2, 2012 8:59 PM | 1 vote
A scholar and a gentleman.
(Microsoft could do well by searching similar forum threads and responding with the correct solution)
Wednesday, April 18, 2012 7:03 AM
This worked for me.
Don't know what's with the Desktop folder.
Friday, April 20, 2012 10:52 PM
Thanks for the info. I have a SSIS package that runs successfully in business intelligence development studio but fails to run under sql server agent as a job. The SSIS package processes an excel file from a file location.
I tried your solution. Only thing that worked for me was the Job ran successfully, but did not process my excel files. Do you know what else could be the problem?
I appreciate your info. Here was my error below before trying your fix. Now I don't get any errors when the job runs. But job did not process excel file:
Executed as user: SCONET\svc_BIGCCPRD84_SSA. Microsoft (R) SQL Server Execute Package Utility Version 10.50.2500.0 for 32-bit Copyright (C) Microsoft Corporation 2010. All rights reserved. Started: 3:31:05 PM Error: 2012-04-18 15:31:10.07 Code: 0xC002F304 Source: Email error Send Mail Task Description: An error occurred with the following error message: "Failure sending mail. System.Net.WebException: Unable to connect to the remote server System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 10.1.1.243:25". End Error Error: 2012-04-18 15:31:10.07 Code: 0x00000001 Source: Unlock workbook Description: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. > System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file '\SCONET\Data\SCO\Group\LGCR Files For Upload\2010-Group 2-12264807800-4112012.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. at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) at ST_22080cd5ccf5484fa05df02546b8d5de.vbproj.ScriptMain.Main() End of inner exception stack trace at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 3:31:05 PM Finished: 3:31:10 PM Elapsed: 4.672 seconds. The package execution failed. The step failed.
Tuesday, May 8, 2012 5:14 PM
Thank you very mcuh !! i struggled for a day with many other solutions, tampering with DCOM and COM settings and got nowhere. I did the "desktop" folder and added permissions and it WORKED !!!!
In my case, we had moved the server from windows 2003 to windows 2008, also we did a .net 2 to .net 4 upgrade. Users were getting the error while trying to use the "Open" on the Interop excel library and getting that error
Tuesday, May 15, 2012 1:55 PM
I'm still having the same problem. I've added the "Desktop" folder, with permissions (even including "Everyone") and also given permission on the DCOM Excel application (to "Everyone" as well in the end).
Error is as below:
Microsoft Excel cannot access the file 'C:\inetpub\wwwroot\spa\Reports\SPPI__2004_.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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Microsoft Excel cannot access the file 'C:\inetpub\wwwroot\spa\Reports\SPPI__2004_.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.
Tuesday, May 22, 2012 9:54 PM
The other problem on my System is where the launching user is not an administrator of local computer: there "saveAs" doesn't work (Desktops have full control for everyone).
Try:
](http://www.c-sharpcorner.com/UploadFile/sushmita_kumari/SecuritySetting101022006023235AM/SecuritySetting1.aspx)I forgot it now, but I have tried any other way, which helped.
Friday, May 25, 2012 11:49 AM
Thanks, Lukasz2891, but that puts me back at the error below. In Windows 7, how do I find the Default Security tab?
Tim
Server Error in '/spa' Application.
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
Friday, May 25, 2012 1:28 PM
I've given "Everyone" permission again, on the DCOM object, and am back to:
Microsoft Excel cannot access the file 'C:\inetpub\wwwroot\spa\Reports\SPPI__2004_.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.
Wednesday, July 4, 2012 10:21 AM
Does anyone here thinks that this could be a security hole at all?
Wednesday, July 25, 2012 12:31 AM
I've found that it works well with only "List folder contents" permission on the systemprofile\desktop folder. For me, the folder was already there, but hidden from my normal user account.
Saturday, September 15, 2012 4:35 PM
Thank you tibb. Your solution worked great for me! No idea why. :-)
Wednesday, December 19, 2012 5:46 PM
Thanks tibb, works for me too. Great!!
Friday, May 10, 2013 9:08 AM
thank you very much. It is very helpful for me.
Friday, September 6, 2013 11:53 AM
Hi All,
Yes, Please create desktop folder in both the below folders if in case your calling application is built in 32 bit and Operation system version is 64 bit.
C:\Windows\SysWOW64\config\systemprofile\Desktop
C:\Windows\System32\config\systemprofile\Desktop
Thanks,
Ganesh Shanmugam.
Monday, September 16, 2013 11:28 PM
Dear Sir. Very thanks for your response. It worked for me. I am using a web application which invokes an executable. Activatign the executable in isolation works fine but from webapp gave that error. Thank you very much.
Monday, October 7, 2013 5:46 AM | 1 vote
Hi Everyone and Tibb,
Thank you so much for this, it saved my life even though I have no understanding of how our issue could be related to the this folder.
However I personally needed some other trick to make this work. I see some people don't manage to fully resolve this issue so I wanted to share my findings as everything is ok on my systems now. Please see below:
- Need to create the Desktop folder as tibb explained
- Needed also to do this: In dcomcnfg, in microsoft excel properties, under the ID tab, I have to set the second option "The launching user".
For me that was the combo fix to do. Failure to do one of these doesn't fully fix the problem.
Also, as I am running a windows service, some machines needed also something else:
- For the Desktop folder, I added NETWORK SERVICE and gave FullControl.
Thank you,
Best of luck to all,
Groaker
Thursday, October 17, 2013 4:59 PM
Thank you so much, Tibb. This worked for me on Windows Server 2008 with Excel 2010. My console application could not open the file when it was submitted by our scheduling package. I added the Desktop folder and gave "Everybody" Full Control -- it's an isolated server so not much is exposed here. I was skeptical because IIS was not involved, but tried it anyway and it paid off!
Thursday, October 24, 2013 8:29 PM
I tried that and the error did not go away. However, after using the management console on the server: Start, Run, then type mmc comexp.msc /32 for the 32-bit version.
We are using impersonation in our ASP.NET application, and using a domain user account.
Then selected Component Services, Computers, my computer, DCOM Config, Microsoft Excel Application. Right click, select Properties. On the Security tab, select Customize for Launch and Acitvation Permissions, and add the domain user. Also added the user on the Identity tab, select "This User", and type the user id and password.
After this, and added the aforementioned folder path, Excel worked fine, opening files.
You are my hero!!!!
Saturday, November 2, 2013 1:53 AM
I was so completely overwhelmed at the absurdity of this solution that I actually took the time to create a Microsoft Live account, set up a username on these forums and post this reply.
This solution works (creating two folders called "Desktop" under the systemprofile folders). It doesn't seem like it should. But it does. *Somehow*
When I first saw this solution proposed on another forum, I skipped over it thinking it was just random nonsense. I even thought in the back of my mind "ooo that sounds fishy, asking me to create folders in my Windows directory" thinking it was some evil programmer at MSoft getting people to set up a hidden backdoor on their servers or something.
Nope!
It's actually how you get past this error when trying to manipulate Excel files via SSIS script task / VB.net / scheduled jobs.
Mama mia!
Thursday, April 16, 2015 8:12 PM
Not sure how you guys figured this out but it works. I used this solution in a Windows app ad it worked as well. Glad I stumbled upon this thread!
Wednesday, May 20, 2015 9:44 PM
Using SQL 2014 with MS Excel 2013 on Windows Server 2008R2. The DCOM edit of both Security and Identity configuration solved my failure to open a file issue (configuring only 1 didn't work). Creating and configuring the "Desktop" folder had no effect (from further up in this thread). Of course the credential needs permissions to the folder - I needed to assert that as well; my domain credential was already a member of the Administrators group on the local server but I had to add it with full permissions to the folder.
Ref keywords: sp_OAMethod Workbooks.Open
Tuesday, November 10, 2015 12:53 PM
Thanks a lot! Applied in my case and now working great!
Monday, November 30, 2015 2:58 PM
Make sure, that
C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files exist**.
**
Tuesday, April 5, 2016 3:37 PM
This doesn't look to be your issue, but maybe this will help others who encounter the same error. I found that the underlying file was corrupted and had to recreate it.
Wednesday, July 18, 2018 6:47 AM
Due to some permission issue application system not able to create Desktop folder. So you can go to directory C:\Windows\SysWOW64\config\systemprofile and **C:\Windows\System32\config\systemprofile ** and then create the Desktop folder manually. And hope it will work.
its working for me after creating Desktop folder manually in both directory.
Thanks