jan*_*n86 0 c# asp.net file-io
我想在我当前用户的桌面文件夹上创建一个文件夹; 我一直收到拒绝访问的消息.我在IIS中的配置文件下有完整的写权限.
string activeDir = @"C:\Users\dmm\Desktop\";
string newPath = System.IO.Path.Combine(activeDir, "mySubDir");
System.IO.Directory.CreateDirectory(newPath);
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
尝试使用内置对象获取桌面路径,并让.NET也处理新文件夹的路径构建.您还需要先检查目录是否存在.
string newFolder = "abcd1234";
string path = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
newFolder
);
if(!System.IO.Directory.Exists(path)) {
try {
System.IO.Directory.CreateDirectory(path);
} catch (IOException ie) {
Console.WriteLine("IO Error: " + ie.Message);
} catch (Exception e) {
Console.WriteLine("General Error: " + e.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5302 次 |
| 最近记录: |