Posts tagged: ASP.NET

Access is Denied Exception when writing to Spreadsheet from ASP.Net

By , September 16, 2009 5:48 pm

I recently got the following error message whilst trying to write to an excel file using the openXML library in ASP.Net and C#:

System.ApplicationException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetRootDir(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.Init(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder..ctor()
at MS.Internal.IO.Packaging.PackagingUtilities.GetDefaultIsolatedStorageFile()
at MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 retryCount, String& fileName)
at MS.Internal.IO.Packaging.SparseMemoryStream.EnsureIsolatedStoreStream()
at MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary()
at MS.Internal.IO.Packaging.CompressEmulationStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.IO.Packaging.CompressStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(String value)
at System.Xml.XmlTextEncoder.Write(String text)
at System.Xml.XmlTextWriter.WriteString(String text)
at System.Xml.XmlAttribute.WriteContentTo(XmlWriter w)
at System.Xml.XmlAttribute.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw)
at System.Xml.XmlDocument.Save(Stream outStream)
at OfficeOpenXml.ExcelWorksheet.Save()
at OfficeOpenXml.ExcelWorkbook.Save()
at xxx.addDataSetToExcel(DataSet DataSetSource, String fileName, String title, String subject, String category, String comments, String fileType)

Turns out that this is in no way a common problem (google was not my friend on this occasion). After nearly an entire day trying to figure this one out I finally came accross the solution and intend to share it here:

The openXML library uses a MemoryStream object when creating the spreadsheet – When the amount of data your putting into your spreadsheet gets too large to be held in memory, it starts to offload the data to disk. This is where the problem arises.

For whatever reason, ASP.NET decides it’s going to try to put the data into an obscure directory that doesn’t always exist – C:\Documents and Settings\Default User\Local Settings\Application Data\IsolatedStorage. I’m not entirely sure why it comes up with Access is Denied, presumabley because the user in the application pool doesn’t have permission to create a directory?

In any case, if you get this problem, just create the above directory and make sure that the user in your application pool (or Everyone) has read and write access to it.

Page Refresh Animations in ASP.NET

By , December 19, 2008 11:33 am

Page Refresh Animations

This refers to the way in which we can display some form of feedback to the user that the page is being updated, without the need for an ugly page flash or the page seemingly doing nothing.

 As always there are several ways to achieve this – a quick google will probably reveal several. Below is probably the most reliable method for our usages.

Continue reading 'Page Refresh Animations in ASP.NET'»

The ASP.NET ViewState…

By , November 6, 2008 3:42 pm

The ViewState in ASP.Net is one of those weird and wonderful things that Microsoft obviously thought was a good idea at the time. Granted, it is quite useful but as with all things like that, it comes with a price – and a fairly hefty one at that if not used sensibly. Continue reading 'The ASP.NET ViewState…'»

Writing Date to Excel from ASP.NET and C#

By , October 31, 2008 11:49 am

Ok, so i’ve just been working on outputting data from an ASP.NET based web app into an Excel Spreadsheet. I’m not going to go into the details of how to do that, but only how to avoid one little problem i encountered.
Continue reading 'Writing Date to Excel from ASP.NET and C#'»

Panorama Theme by Themocracy