views:

1147

answers:

3

Here is my code,

Dim allFiles As FileInfo() = 
                        tempDir.GetFiles("*.pdf", SearchOption.AllDirectories)

I've googled and found that I need to change the permissions of my app from Project properties > View UAC Settings > and change level to level="requireAdministrator"

But its also not working. I found something about FileIOPermission class, but dont know how to implement it.

==> Detailed code.

Dim tempDir As New DirectoryInfo(path)
        Dim FileDetails(4) As String
        Dim iTem As ListViewItem
        If (tempDir.Attributes <> FileAttributes.System) Then
            Dim allFiles As FileInfo() = tempDir.GetFiles("*.pdf", SearchOption.AllDirectories)
            Dim oneFIle As FileInfo
            For Each oneFIle In allFiles
                FileDetails(0) = oneFIle.Name()
                FileDetails(1) = oneFIle.FullName()
                FileDetails(2) = oneFIle.Length() / (1024 * 1024)
                FileDetails(2) = FileDetails(2).Remove(5)
                iTem = New ListViewItem(FileDetails)
                ListView1.Items.Add(iTem)
            Next
        End If

Path is a string that contains the path required, in this case G:\

+1  A: 

You won't find PDF files in this folder:

The System Volume Information folder is a hidden system folder that the System Restore tool uses to store its information and restore points. (MSDN)

So just ignore it.

Granted, GetFiles() does not allow you to ignore files/folders, so you'd have to PInvoke into FindFirstFile et al. to do searches effectively.

Anton Gogolev
Only the SYSTEM account has access to this folder.
Igor
So, I cannot ignore that folder.. Ok, Can you provide a modified `simple` code to accomplish what I want?
Bibhas
A: 

System Volume Information Folder is a O/S protected folder. Even though you may have administrative access, you still will not be able to access it. You can try it from Explorer itself. (Need to enable option to show protected Operating System files.)

Vivek
Actually, I want to search all the folder other that itself..
Bibhas
A: 

Ok, I think I solved the case, I just iterated each folder, checked their attributes and then added to the list.. I think it's working.. Plz check it a bit..

Dim tempDir As New DirectoryInfo(path)
    Dim FileDetails(4) As String
    Dim iTem As ListViewItem
    Try
        Dim allFiles As FileInfo() = Nothing 
        For Each Directory In tempDir.GetDirectories()
            Try
                If (Directory.Attributes <> FileAttributes.System) Then
                    allFiles = Directory.GetFiles("*.pdf", SearchOption.AllDirectories)
                End If
                Dim oneFIle As FileInfo

                For Each oneFIle In allFiles
                    FileDetails(0) = oneFIle.Name()
                    FileDetails(1) = oneFIle.FullName()
                    FileDetails(2) = oneFIle.Length() / (1024 * 1024)
                    FileDetails(2) = FileDetails(2).Remove(5)
                    iTem = New ListViewItem(FileDetails)
                    ListView1.Items.Add(iTem)                        
                Next
            Catch ex As Exception

            End Try
        Next
    Catch ex As UnauthorizedAccessException

    End Try
Bibhas