Last post Jul 28, 2009 08:53 AM by Thomas Sun – MSFT
Jul 21, 2009 02:05 PM|NiravVyas|LINK
I am having a web Application where I need to export some data to excel sheet.I have some methods that export the grid data to Excel but as I need to generate the Excellsheet in a specific format I had to use
Everything worked fine when I ran application on my local system.But when I Upload the applcaition on server.It raises error which goes.. "That assembly does not allow partially trusted callers". I found that It needs to deal with trust level.But can't figure
I would also like to mention that I am using a shared hosting server. Any help would be appreciable.
Jul 21, 2009 02:56 PM|Venkatesh Mndya|LINK
It is not recommended to use Microsoft.Office.Interop.Excel library for export to excel functionality without having office tools installed in your machine(either local or server).
Have a look at below article
Jul 22, 2009 06:08 AM|NiravVyas|LINK
Thanks for reply,
But it is required by the person for whom I am developing the application,there must be some way out or say some alternative.
Jul 22, 2009 06:53 AM|Venkatesh Mndya|LINK
The one word answer to your question is 'It is impossible to have export to excel functionality by just including Microsoft.Office.Interop.Excel library in your application'.
And also if you try to install office tools on the server for excel functionality, it affects the performance of your page if the data contention is high. There are other number of disadvantages too.
If you would like some alternative sollutions, you can considor below third party tools,
Carlsoag Excelxml writer(free library)
Why dont you directly use below code instead of using excel library,
private void ExportGridView()
string attachment =
Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw =
System.Web.UI.HtmlTextWriter htw =
Jul 22, 2009 11:02 AM|NiravVyas|LINK
I have had that code already but as I said earliar I had to generate the excel in a specific format,and also i need to have multiple worksheets,which I am not sure can be done by the function you wrote.Thats why I had to deal with interop library.Thanks
again for the reply.
Jul 22, 2009 01:21 PM|Venkatesh Mndya|LINK
No. We cant have multiple worksheets with the function that i sent.
Jul 27, 2009 07:18 AM|Thomas Sun – MSFT|LINK
During development in local, the code access security is Full trust level by default and application can implement more works. You can run your website with Full trust level in web.config:
<trust level="Full" />
For more information, see
http://msdn.microsoft.com/en-us/library/ms998326.aspx (Typically, Table 4: Default ASP.NET Policy Permissions and Trust Levels).
I look forward to receiving your test results.
Jul 28, 2009 05:42 AM|NiravVyas|LINK
Thanks for your reply.I did try adding the trust level but no lucks.I found some stuff on net which says you can not set this permissions if you are using shared hosting server.And also it is not recommendable my microsoft as you can see the link in above
Jul 28, 2009 08:53 AM|Thomas Sun – MSFT|LINK
Thanks for your response.
Yes, most host servers use Medium trust level to restrict which resource types your application can access and which privileged operations it can perform for security.
You can try to find out some host servers that allow you to use Full Trust level on internet.