简体   繁体   English

从Windows 8.1进行文件访问

[英]File access from Windows 8.1

I using C# for making an app. 我使用C#制作应用程序。 I want to access pictures form user system by using that code. 我想使用该代码从用户系统访问图片。 Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+ "//FolderName" . Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+ "//FolderName" It was working fine on windows 10. But if we use that code in windows 8.1. 在Windows 10上运行正常。但是,如果我们在Windows 8.1中使用该代码。 It will generate "unauthorizedaccessexception" of path.Kindly help me to get ride of that problem. 它将生成path的“ unauthorizedaccessexception”。请帮助我解决该问题。

Do you really use two forward slashes? 您是否真的使用两个斜杠? I wonder that this worked at all. 我不知道这是否奏效。 You should use backslashes. 您应该使用反斜杠。 Also, always use System.IO.Path.Combine(...) to construct paths. 另外,请始终使用System.IO.Path.Combine(...)构造路径。 Your code will also fail (with forward or backward slashes after the + ), if the part before the + already contains a backslash at the end. 如果+之前的部分的末尾已经包含反斜杠,则您的代码也会失败( +后面带有正斜杠反斜杠)。 System.IO.Path.Combine(...) takes care of this. System.IO.Path.Combine(...)负责此工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM