OpenXML, IsolatedStorage, NETWORK SERVICE and Windows Server 2008
I have a large web application. One very small piece of this web application generates XLSX files using the OpenXML library (written in C#).
I've run into the problem described in this post: IsolatedStorage Access Denied
However, the instructions there are for Windows Server 2003, and the user directory hierarchy in 2008 is different.
I've tried creating the IsolatedStorage directory in these locations (and then giving NETWORK SERVICE permissions to it):
C:\Users\Default\AppData\Local\IsolatedStorage C:\Users\Default\AppData\Roaming\IsolatedStorage
Those did not work. I've tried to find where the appropriate location for the IsolatedStorage directory is on Windows Server 2008 (generally using Google and specifically here) without success.
Can anyone tell me where I should create that directory (or alternatively, suggest some other solution that would force OpenXML to instruct the archive library to not use IsolatedStorage to create the spreadsheet)?
Edit - July 14, 2011 - Adding the exception message and stack trace so it will hopefully help others find this.
Exception: System.ApplicationException
Message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Source: mscorlib
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.Zip.ZipIOFileItemStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Compression.DeflateStream.InternalWrite(Byte[] array, Int32 offset, Int32 count, Boolean isAsync)
at System.IO.Compression.DeflateStream.Write(Byte[] array, 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.Xml.XmlUtf8RawTextWriter.FlushBuffer()
at System.Xml.XmlUtf8RawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)
at DocumentFormat.OpenXml.OpenXmlElement.WriteAttributesTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
at DocumentFormat.OpenXml.OpenXmlPartRootElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlPartRootElement.SaveToPart(OpenXmlPart openXmlPart)
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.SavePartContents()
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose(Boolean disposing)
at DocumentFormat.OpenXml.Packaging.Ope开发者_运维百科nXmlPackage.Close()
During my research, I stumbled across this blog post as well: http://www.kevinrohrbaugh.com/blog/tag/openxml
I dismissed it at first since it's not possible for me to have my application impersonate another user, due to the way it interacts with another web application that I have no control over.
However, I got to thinking that perhaps it I got rid of the registry entry for NETWORK SERVICE in ProfileList, I could get the same result.
So, I renamed HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20 to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20-backup and re-ran my Excel export and it is working properly. As far as I can tell I don't have any negative results from having done this.
[I would have added this as a comment, but I don't have permission...]
I hope this helps someone else...
I have an app running in IIS Express as Network Service on Windows Server 2008 R2. The isolated storage store that is returned from calling IsolatedStorageFile.GetMachineStoreForDomain() is located at: c:\ProgramData\IsolatedStorage
精彩评论