Vb.net ACL特殊文件夹 [英] Vb.net ACL special folder
问题描述
我们!我要将特定文件(xlsx)搜索到我的文档文件夹中,
但我收到有关权限的错误。我将vb.net设置为管理员
感谢您的帮助!
我的尝试:
Dim FolderPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim directory = FolderPath
Dim files()As System.IO.FileInfo
Dim dirinfo As New System.IO.DirectoryInfo(目录)
files = dirinfo.GetFiles(xlsx,IO.SearchOption.AllDirectories)错误行:
$ b
在mscorlib.dll中的'eccezione non gestita di tipo'System.UnauthorizedAccessException'
对于每个文件在文件中
ListBox1.Items.Add(文件)
下一页
End Sub
I guys! 'm tring to search specific file(xlsx) into my document folder,
but i get error about permission.I set the vb.net ication as Administrator
Thanks for any help!
What I have tried:
Dim FolderPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim directory = FolderPath
Dim files() As System.IO.FileInfo
Dim dirinfo As New System.IO.DirectoryInfo(directory)
files = dirinfo.GetFiles("xlsx", IO.SearchOption.AllDirectories) error line:
Eccezione non gestita di tipo 'System.UnauthorizedAccessException' in mscorlib.dll
For Each file In files
ListBox1.Items.Add(file)
Next
End Sub
推荐答案
xlsx搜索规范应该是* .xlsx。
另外,你的MyDocuments路径中有一个文件夹这对你来说是禁区。您启动的代码始终以您的身份运行,因此它具有您所执行的完全相同的权限。例如,您无法搜索路径C:\
That "xlsx" search spec should be "*.xlsx".
Also, you've got a folder in your MyDocuments path somewhere that is off-limits to you. The code you launch always runs as you so it has the exact same permissions you do. For example, you can't search the path "C:\
Recycle.Bin\S-1-5-18。尝试这样做会导致你得到的错误。
要么不搜索AllDirectories,要么编写自己的搜索来处理异常和继续前进,忽略失败的文件夹路径。这并不难。
Recycle.Bin\S-1-5-18". Attempting to do so will result in the error you're getting.
Either don't search "AllDirectories", or you write your own search that handles the exception and keeps going, ignoring the folder paths that fail. It's not that hard.
这篇关于Vb.net ACL特殊文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!