Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Response.AddHeader("content-disposition", "attachment;filename= Salary Slip.xls")
       Response.ContentType = "application/octectstream"

       Dim path As String = Server.MapPath("~/exportedfiles")
       If (Directory.Exists(path) = False) Then
           Directory.CreateDirectory(path)
       End If
       File.Delete(path + "Salary Slip.xlsx")


       Dim xlAppToExport As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
       xlAppToExport.Workbooks.Add("")


       Dim xlWorkSheetToExport As Excel.Worksheet
       xlWorkSheetToExport = DirectCast(xlAppToExport.Sheets("Sheet1"), Excel.Worksheet)
Posted
Updated 21-Jan-16 20:29pm
v4
Comments
Sinisa Hajnal 22-Jan-16 2:53am    
The user who is logged in in your app (or the application account itself) has no access to server folder (and rightly so). You have to create public folder on the server for such access or provide a safe way to download and upload the file.
neeraj_ 22-Jan-16 3:51am    
sir my data is not in a foder
thats are simple label value in asp:table control
which i want to download in a excel sheet
F-ES Sitecore 22-Jan-16 4:03am    
What line throws the exception? Also what you're doing (automating Excel) isn't supported, it might work ok on your local machine but it's not going to work on a production environment, and you're almost certainly in violation of your license agreement.
neeraj_ 22-Jan-16 4:26am    
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)).
F-ES Sitecore 22-Jan-16 4:47am    
I asked what line the error occurs on.

Hey hi,

The problem here is about setting the rights on the server,

On server you need to set the access rights to the Network User,
Please provide the rights to the IUSR and the Network User, also provide
the Network user to the folder in which the file is present.

The issue is caused because of access right conflicts.
 
Share this answer
 
When you code interop object in web based application, when you deploy your code in IIS you need below access permission/settings.
This is a COM permissions problem.
follow below steps
1.Start > Run > dcomcnfg (or "mmc -32" and then add the Component Services snap-in manually if you can’t find the app under step 3)
2.Navigate to Component Services > Computers > My Computer > DCOM Config
3.Locate the MS application giving you trouble (eg: "Microsoft Excel Application" for Excel or "Microsoft Word 97 – 2003 Document" for Word)
4.Right click > Properties
5.On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
6.Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
------------------------------------

This seems to be an issue with Excel/Word/etc not having access to a profile when being started via the interop route.
1.Open Windows Explorer
2.Depending on whether you installed a 32bit or 64bit version of office you will need to do one  (or both) of the following:
1.32bit Office installation: Navigate to C:\Windows\System32\config\systemprofile
2.64bit Office installation: Navigate to C:\Windows\SysWOW64\config\systemprofile
3.Verify the folder "Desktop" exists (create it if it's not there)
4.Right click > Properties
5.On the security tab: Add the account under which the site is running (eg: Network Service) with default permissions (Read & execute; List folder contents; Read)
 
Share this answer
 
v2

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