我试图使用以下方法创建一个目录,在应用程序中按下按钮后触发它,并向其中添加文件:
DirectoryInfo d = new DirectoryInfo(@"..\\newFolder\\");
FileInfo f = new FileInfo(@"..\\newFolder\\foo.txt");
if (!d.Exists)
{
d.Create();
}
if (!f.Exists)
{
f.Create().Dispose();
}
以下是我在进行这个操作时在我的通用应用程序中遇到的错误信息:
An exception of type 'System.UnauthorizedAccessException'
occurred in System.IO.FileSystem.dll but was not handled in user code
Additional information: Access to the path
'C:\Users\[username]\Documents\MyApp\bin\x86\Debug\AppX\newFolder' is denied.
有谁熟悉这个错误或者有什么建议吗?
编辑 除了以下内容,这是一个在Windows 10通用应用程序环境中处理文件系统的好资源:文件访问和权限(Windows运行时应用程序)https://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh758325.aspx
@"..."
语法,则无需转义反斜杠。@"..\newFolder\"
即可。 - theB