c# - OpenXML、IsolatedStorage、网络服务和 Windows Server 2008

标签 c# windows-server-2008 openxml isolatedstorage

我有一个大型网络应用程序。此 Web 应用程序的一小部分使用 OpenXML 库(用 C# 编写)生成 XLSX 文件。

我遇到了这篇文章中描述的问题:IsolatedStorage Access Denied

但是,Windows Server 2003 的说明和 2008 中的用户目录层次结构不同。

我尝试在这些位置创建 IsolatedStorage 目录(然后向其授予 NETWORK SERVICE 权限):

C:\Users\Default\AppData\Local\IsolatedStorage C:\Users\Default\AppData\Roaming\IsolatedStorage

那些没有用。我试图找到 IsolatedStorage 目录在 Windows Server 2008 上的适当位置(通常使用 Google,特别是此处),但没有成功。

谁能告诉我应该在哪里创建该目录(或者建议一些其他解决方案,强制 OpenXML 指示存档库不使用 IsolatedStorage 创建电子表格)?

编辑 - 2011 年 7 月 14 日 - 添加异常消息和堆栈跟踪,希望能帮助其他人找到它。

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.OpenXmlPackage.Close()

最佳答案

在我的研究过程中,我也偶然发现了这篇博文:http://www.kevinrohrbaugh.com/blog/tag/openxml

起初我拒绝了它,因为我无法让我的应用程序模拟另一个用户,因为它与我无法控制的另一个 Web 应用程序交互的方式。

但是,我开始思考,也许我去掉了 ProfileList 中 NETWORK SERVICE 的注册表项,我可以获得相同的结果。

因此,我将 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20 重命名为 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20-backup并重新运行我的 Excel 导出,它工作正常。据我所知,这样做没有任何负面结果。

关于c# - OpenXML、IsolatedStorage、网络服务和 Windows Server 2008,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6679193/

相关文章:

c# - ListView 数据不会在 WPF 应用程序中刷新

c# - 如何在 C# 的通用抽象类中定义类型 T 必须具有字段 “ID”

c# - Open-XML 保存 word 文档产生损坏的文件

c# - 在 ASP.NET 中运行 shell 命令

c# - 将上传的文件存储在数据库中或将其存储在文件系统中哪个好

windows-server-2008 - 我可以在不安装.Net Framework 4.5的情况下安装MVC4吗

batch-file - Windows 2008 服务器任务调度程序不运行 .bat 批处理作业

php - 获取 $_SERVER ['AUTH_USER' 的空白值]

xml - OOXML : How is a table header (heading) encoded?

c# - 如何嵌入 Google Docs 或 Office 365 编辑器?