Vb.Net未经授权的访问异常 [英] Vb.Net unauthorized access exception

查看:82
本文介绍了Vb.Net未经授权的访问异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我一直在尝试编写一个使用OpenXML docmentformat生成Word文档的小程序。



在我的mainform中,我有一个创建文档的方法:

Hello,

I have been trying to write a small program that generates a Word document using OpenXML docmentformat.

In my mainform I have a method creating the document:

' Creates a WordprocessingDocument.
Public Sub CreatePackage(filePath As String, text As String)
    Using package As WordprocessingDocument = WordprocessingDocument.Create(_filename, WordprocessingDocumentType.Document)
        ' Add a new main document part.
        package.AddMainDocumentPart()

        ' Create the Document DOM.
        package.MainDocumentPart.Document = New Document(New Body(New Paragraph(New Run(New Text(text)))))

        ' Save changes to the main document part.
        package.MainDocumentPart.Document.Save()
    End Using
End Sub





当我运行程序时,我得到一个UnauthorizedAccessException访问路径'C:\ Temp'被拒绝。



我试过搜索网但是有51.000次点击这基本上不可能全部审查。我的安排和迄今为止我检查的内容:

* Windows 7 Pro

* Visual Studio 2010(以管理员身份运行)

*我有PC上的管理员权限

*尝试使用



When I run the program I get a "UnauthorizedAccessException" Access to the path 'C:\Temp' is denied.

I have tried searching the net but with 51.000 hits on this basically impossible to review them all. My settup and what I have checked so far:
* Windows 7 Pro
* Visual Studio 2010 (running as admin)
* I have admin rights on PC
* tried to add a app.manifest with

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />





任何帮助都会赞赏。



Any help would appreciated.

推荐答案

我猜C:\ Temp是一个现有的文件夹,并希望您正确设置访问权限 - 因此C:\ Temp不是文件的可接受名称。

我看到你的函数使用 CreatePackage(filePath As String ,而你调用 WordprocessingDocument.Create(_filename 。您是否混淆了文件名?在您具有写入权限的文件夹中尝试不存在的文件名。
I guess C:\Temp is an existing folder, and hopefully you set the access rights correctly - hence C:\Temp is not an acceptable name for a file.
I see that your function uses CreatePackage(filePath As String while the you call WordprocessingDocument.Create(_filename. Did you mix up the filenames? Try a non-existing filename in a folder where you have write access.


这篇关于Vb.Net未经授权的访问异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆