Ciao a tutti,
sto cercando di creare una applicazione per cercare file e testo. Tutto va bene, ma non riesco a far funzionare la mia app a causa dell'eccezione 'Accesso negato alla cartella..' che accade quando voglio cercare all'interno delle cartella Documenti. In particolare il mio programma si inceppa a causa della inaccessibilità delle sottocartelle 'Immagini', 'Musica' e 'Video'.
La routine che uso è:
Ma ho usato anche:codice:Try Dim folderName As String = Nothing If (Environment.GetCommandLineArgs.Length > 1) Then folderName = Environment.GetCommandLineArgs(1) End If ' Set a variable to the My Documents path. Dim txtFiles = Directory.EnumerateFiles(folderName, "*.*", opt) For Each namo As String In txtFiles Dim readText As String = File.ReadAllText(namo) If readText.Contains(TextBox1.Text) Then ImageList1.ColorDepth = ColorDepth.Depth32Bit Dim sh As New NativeMethods.SHFILEINFO sh = NativeMethods.GetInfoFromShell(namo.ToString) Dim theIcon As Icon If sh.hIcon <> IntPtr.Zero Then listView1.LargeImageList = ImageList1 listView1.SmallImageList = ImageList1 listView1.View = View.SmallIcon theIcon = DirectCast(System.Drawing.Icon.FromHandle(sh.hIcon).Clone, System.Drawing.Icon) ImageList1.Images.Add(namo.ToString, theIcon.Clone) listView1.Items.Add(namo.ToString, namo.ToString) End If End If remov() listView1.View = View.Details Next
Con quest'ultima routine sono riuscito a vedere le cartelle incriminate, che invece non riesco a vedere se vado a mano nella cartella Documenticodice:Dim lstResult As New ListView Dim stkStack As New Stack(Of String) stkStack.Push("C:\Users\giorg\Documents") Do While (stkStack.Count > 0) Dim strDirectory As String = stkStack.Pop Try Dim strDirectoryName As String For Each strDirectoryName In Directory.GetFiles(strDirectory) listView1.Items.Add(strDirectoryName) Next Catch ex As UnauthorizedAccessException MsgBox(ex.Message) End Try Loop
Qualcuno ha un'idea su come posso evitare questo problema?
Grazie a tutti in anticipo

Rispondi quotando