SharePoint生产服务器中使用Open XML 2.5创建Word文档触发权限异常的问题求助
大家好,我最近碰到一个困扰很久的问题,想请各位前辈帮忙分析下:
我有一个用Visual Basic开发的SharePoint应用,在开发机器上使用Open XML 2.5创建Word文档完全正常。但最近部署到新搭建的生产服务器后,其他功能都没问题,唯独生成Word格式报告的代码失败了,报错卡在这一行:
Dim wpd As WordprocessingDocument = WordprocessingDocument.Create(MemStream, WordprocessingDocumentType.Document, True)
对应的完整函数代码如下:
''' <summary> ''' ''' </summary> ''' <param name="MemStream"></param> ''' <returns></returns> Public Function WPDCreateFromStream(MemStream As MemoryStream) As WordprocessingDocument Try Dim wpd As WordprocessingDocument = WordprocessingDocument.Create(MemStream, WordprocessingDocumentType.Document, True) Dim MainPart As MainDocumentPart = wpd.AddMainDocumentPart() MainPart.Document = New Document() Dim DocBody As New Body() Return wpd Catch ex As Exception WriteErrorToEventLog("OpenXML", "WPDCreateFromStream", "", ex) Return Nothing End Try End Function
触发的异常详情如下:
ERROR: Source: OpenXML Routine: WPDCreateFromStream User: Message: The type initializer for 'MS.Utility.EventTrace' threw an exception. StackTrace: at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID) at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming) at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.CreateCore(Stream stream) at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(Stream stream, WordprocessingDocumentType type, Boolean autoSave) at FIS.SP.PSTARProjectTracker.PSTAR.Core.BusinessLogic.OpenXML.WPDCreateFromStream(MemoryStream MemStream) Source: WindowsBase Data: System.Collections.ListDictionaryInternal InnerException: System.Security.SecurityException: Requested registry access is not allowed. at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue) at MS.Utility.EventTrace.IsClassicETWRegistryEnabled() at MS.Utility.EventTrace..cctor() The Zone of the assembly that failed was: MyComputer ToString: System.TypeInitializationException: The type initializer for 'MS.Utility.EventTrace' threw an exception. ---> System.Security.SecurityException: Requested registry access is not allowed. at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue) at MS.Utility.EventTrace.IsClassicETWRegistryEnabled() at MS.Utility.EventTrace..cctor() --- End of inner exception stack trace --- at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID) at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming) at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.CreateCore(Stream stream) at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(Stream stream, WordprocessingDocumentType type, Boolean autoSave) at FIS.SP.PSTARProjectTracker.PSTAR.Core.BusinessLogic.OpenXML.WPDCreateFromStream(MemoryStream MemStream) TargetSite: Void EasyTraceEvent(Keyword, Event)
我确定代码本身没问题,因为在开发服务器上已经稳定运行了一年多。我猜测是生产服务器的权限问题,或者DocumentFormat.OpenXML.dll的安装/注册有问题,但搜了很久都没找到解决方案。
我已经尝试过这些操作:
- 在生产服务器上安装了Open XML 2.5和生产力工具,工具能正常打开Word文档,但应用还是报同样的错;
- 确认
DocumentFormat.OpenXML.dll已经随.wsp包部署到服务器上,也单独安装过Open XML 2.5,但问题依旧; - 考虑过MemoryStream的传递方式,试过显式用ByVal,但没有变化;
- 代码是创建新文档,所以用的是
WordProcessingDocument.Create,这个逻辑在开发环境是对的。
越想越觉得是权限问题,但不知道具体该给哪个账号加什么权限,或者有没有其他组件没配置好?如果各位有遇到过类似问题,还请指点一下,非常感谢!
备注:内容来源于stack exchange,提问作者Kevin
相关产品推荐
相关产品推荐

