I'm working on a WPF application where the user sets the target path for an xml file to be created, but I'm always getting an UnauthorizedAccessException, even if the target directory is in my own computer. I've already tried replacing <requestedExecutionLevel level="asInvoker" uiAccess="false" />
with <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
in the app.manifest file to force the program to run as administrator but it didn't work either. The exception message I get is
我正在开发一个WPF应用程序,其中用户设置要创建的xml文件的目标路径,但是我总是得到一个UnauthorizedAccessException,即使目标目录在我自己的计算机中也是如此。我已经尝试用app.manifest文件中的
Access to the path [path] is denied
访问路径[path]被拒绝
What do I need to do to solve this problem?
我该怎么做才能解决这个问题?
Thank you.
1 个解决方案
#1
0
The solution I found for this issue was to create a folder inside the target directory set by the user with the following code:
我找到的解决此问题的方法是在用户设置的目标目录中创建一个文件夹,其中包含以下代码:
DirectoryInfo info = Directory.CreateDirectory(myPath);
DirectoryInfo info = Directory.CreateDirectory(myPath);
Then, set the program to create the xml file inside that newly created folder.
然后,设置程序以在新创建的文件夹中创建xml文件。
#1
0
The solution I found for this issue was to create a folder inside the target directory set by the user with the following code:
我找到的解决此问题的方法是在用户设置的目标目录中创建一个文件夹,其中包含以下代码:
DirectoryInfo info = Directory.CreateDirectory(myPath);
DirectoryInfo info = Directory.CreateDirectory(myPath);
Then, set the program to create the xml file inside that newly created folder.
然后,设置程序以在新创建的文件夹中创建xml文件。