怎么让读者只读? C# [英] How get girectories read only ? C#

查看:169
本文介绍了怎么让读者只读? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码选择路径并获取其所有子目录







i use this code to select a path and get all subdirectories of it



if (FBD_devis.ShowDialog() == DialogResult.OK)
             {
                 try
                 {

                DirectoryInfo diri_info = new DirectoryInfo(FBD_devis.SelectedPath);

                     listBox2.Items.AddRange(diri_info.GetDirectories("*",    SearchOption.AllDirectories));

                 }
                 catch (UnauthorizedAccessException u)
                 {
                     MessageBox.Show("le problème c'est a cause ce Dossiers: " + u.Message + "\n" + u.Source);

                 }
             }
         }





但是当我选择时路径

[ ^ ]



它会产生这个问题

[ ^ ]



how我可以解决这个问题吗?



我尝试了什么:



我试图寻找如何忽略这种类型的目录,但我无法解决问题。



but when i select the path
[^]

it generate this problem
[^]

how can I fix this problem please ?

What I have tried:

I tried to look for how to ignore this type of directories but I could not solve the problem.

推荐答案

所以你的问题是你的应用程序没有适当的权限访问c:\ usersrs \ inconnu \documents\ma音乐。您的第一个屏幕截图仅显示文档文件夹的快捷方式(这没有多大帮助)。



这里的解决方案是以管理员权限运行代码,如图用户将运行您的应用程序并为该目录分配适当的权限,或选择不需要提升权限访问该目录的其他文件夹。



您没有指定这是一个Web应用程序,还是指定为winforms / desktop应用程序,只能将表单视为标记。如果它是一个webforms应用程序,我强烈建议您不要让您的Web应用程序以这种方式访问​​您的本地目录,它会成为一个安全问题。



运行管理员/强制运行的一些链接作为管理员



c# - 如何强制我的.NET应用程序以管理员身份运行? - 堆栈溢出 [ ^ ]



谷歌 [ ^ ]
So your problem is your application doesn't have proper permissions to access c:\users\inconnu\documents\ma music. Your first screenshot only shows the shortcut to your documents folder (which doesn't help much).

Your solution here is to either run your code with administrator privileges, figure out what user is going to run your app and assign proper permissions to the directory, or choose a different folder that doesn't require elevated permissions to access that directory.

You don't specify if this is a web app or if it as winforms/desktop app, only see "forms" as a tag. If it is a webforms app i would highly recommend you don't allow your web application access to your local directories in this manner, it becomes a security issue among other things.

Some links for running as admin/forcing run as admin

c# - How do I force my .NET application to run as administrator? - Stack Overflow[^]

Google[^]


这篇关于怎么让读者只读? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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